Php 形式:发布字符串&;是否在同一表单字段中获取结果?
是否可以在表单字段中发布字符串,并在同一表单字段中获取转换后的字符串结果 我使用代码:Php 形式:发布字符串&;是否在同一表单字段中获取结果?,php,oop,web-applications,webforms,Php,Oop,Web Applications,Webforms,是否可以在表单字段中发布字符串,并在同一表单字段中获取转换后的字符串结果 我使用代码: <?php $string=''; if (isset($_POST['string'])) $string=$_POST['string'] if (isset($_POST['DoStuff'])) { $string = doStuffWithThisString($string); } if (isset($_POST['DoOtherStuff']))
<?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 echo $string; ?>
我不明白为什么它不起作用。根据浏览器的不同,按钮名称可能不是“DoStuff”和“DoOtherStuff”。例如,在IE中,它将是$\u POST['DoStuff\u x']
和$\u POST['DoStuff\u y']
做一个print\r($\u POST)
查看表单数据的发布方式。如果您在提交字段中使用相同的名称,在$\u POST['name']中重新加载页面时,您将获得单击的值
我认为这是问题的解决办法,但有人能证实这一点吗