回应字符串中的表单

时间:2012-05-11 21:23:44

标签: php html

我有一个应该运行特定次数的echo语句,即'n'次,现在函数abc()为空,出于测试目的,我正在尝试的是: -

echo "
<form  method=\"post\" action=\"<?php abc(); ?>\"  >
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /> <br/>
<input type='submit' value='submit comment' style='margin-left:60px' />
</form>
";

但每次点击按钮提交表单我都会收到错误

  

禁止

     

您无权访问/&lt;在这台服务器上。

如果我想做的事情不可能,还有其他办法吗?

我想做的是;创建一个按钮,当单击它时,调用一个PHP函数(可能会或可能不会重新加载页面,并不重要)。将通过循环创建多个函数,并且对于每个循环迭代,传递给函数的值将是不同的。通过值,我不是指变量类型,我的意思是变量值会有所不同。我知道目前没有任何变量传递给abc函数,但就像我说的那样,abc函数仅用于测试以试图超越禁用错误。

我实际上要做的是这个......

$doubleinverted='"';
echo "
<form action=".$doubleinverted."<?php f_comment(".$row['ScrapId'].",'".$row1['Email']."');?>".$doubleinverted." method='post'>
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /><br/>
<input type='submit' value='submit comment' style='margin-left:60px' />    
</form>
";

我知道你可以添加像\"这样的引号,但我发现了这一点。

此外,此echo语句将处于循环中,并且对于每次迭代,传递给函数的值将是不同的

3 个答案:

答案 0 :(得分:3)

您不能在echo语句中使用PHP块。

如果f_comment回显一个字符串,你应该按照以下方式做一些事情:

echo "blah blah blah";
f_comment(...);
echo "more blah blah";

如果返回值,则将其存储在变量中或连接字符串:

$string = "blah blah blah";
$string .= f_comment(...);
$string .= "more blah blah";

echo $string;

答案 1 :(得分:0)

echo "
<form  method=\"post\" action=\"<?php abc(); ?>\"  >
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /> <br/>

<input type='submit' value='submit comment' style='margin-left:60px' />

</form>

";

当您处于PHP模式时,表单的操作为<?php abc(); ?>。我恐怕我不能让你做那个戴夫!

将表单更改为<form method=\"post\" action=\"' . abc() . '\" >

答案 2 :(得分:0)

当你在这里时,摆脱逃避的混乱报价。这读得更清楚......

<?php
    echo '<form  method="post" action="' . abc() . '">
    <input type="text" name="comment" style="width: 80%;height: 70px; margin-left: 60px" /> <br/>

    <input type="submit" value="submit comment" style="margin-left:60px" />

    </form>';
?>
相关问题