开发者

Form: POST a string & get the result in the same form field?

Is to possible to POST a string in the form field and get converted string result in the same form field?

I use the code:

<?php
  $string='';
  if (isset($_POST['string']))
    $string=$_POST['string']

  if (isset($_POST['DoStuff']))
  {
    $string = doStuffWithThisString($string);
  }
  if (isset($_POST['DoOtherStuff']))
  {
    $string = doOtherStuffWithThisString($string);
  }

?>

开发者_运维知识库<form action="" method="post">
<!-- blank action attribute will post form to the current page-->
  <input type="text" value="<?=$string?>" name="string" />
<!-- <?=$string?>  is the same as <?php echo $string; ?> -->
  <input type="submit" value="Do Stuff" name="DoStuff" />
  <input type="submit" value="Do Other Stuff" name="DoOtherStuff" />
</form>

but get the result above form field...


Are you sure short tags are enabled?

See: http://php.net/manual/en/ini.core.php

If they are not, just use:

<?php echo $string; ?>

I don't see why it wouldn't work.


Depending on the browser, the button names may not be "DoStuff" and "DoOtherStuff". For example, in IE it will be $_POST['DoStuff_x'] and $_POST['DoStuff_y'].

do a print_r($_POST); to see what the form data is being posted as.


If you would use the same name in the submit fields, upon page reload in $_POST['name'] you would get the value you clicked on.

I think that's the solution to the issue, but can someone confirm this ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜