【问题标题】:Form: POST a string & get the result in the same form field?表单:POST 一个字符串并在同一个表单字段中获取结果?
【发布时间】:2010-12-23 17:38:33
【问题描述】:

是否可以在表单字段中发布字符串并在同一表单字段中获取转换后的字符串结果?

我使用代码:

<?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>

但是得到表单域上方的结果...

【问题讨论】:

    标签: php oop web-applications webforms


    【解决方案1】:

    您确定启用了短标签吗?

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

    如果不是,请使用:

    <?php echo $string; ?>
    

    我不明白为什么它不起作用。

    【讨论】:

      【解决方案2】:

      根据浏览器的不同,按钮名称可能不是“DoStuff”和“DoOtherStuff”。例如,在 IE 中为$_POST['DoStuff_x']$_POST['DoStuff_y']

      发送print_r($_POST); 以查看表单数据的发布内容。

      【讨论】:

        【解决方案3】:

        如果您在提交字段中使用相同的名称,则在 $_POST['name'] 中重新加载页面时,您将获得您点击的值。

        我认为这是问题的解决方案,但有人可以确认吗?

        【讨论】:

          猜你喜欢
          • 2015-06-25
          • 2014-02-20
          • 2014-01-20
          • 1970-01-01
          • 2010-10-17
          • 1970-01-01
          • 1970-01-01
          • 2019-11-21
          • 2020-02-14
          相关资源
          最近更新 更多