我正在尝试从表单操作中的 PHP 脚本运行一个函数。
我的代码:
<?php
require_once ( 'username.php' );
echo '
<form name="form1" method="post" action="username()">
<p>
<label>
<input type="text" name="textfield" id="textfield">
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit">
</label>
</p>
</form>';
?>
我回显了表单,但我希望执行从 username.php 调用的函数“username”。我怎样才能以与上述类似的方式做到这一点?
最佳答案
<?php
require_once ( 'username.php' );
if (isset($_POST['textfield'])) {
echo username();
return;
}
echo '
<form name="form1" method="post" action="">
<p>
<label>
<input type="text" name="textfield" id="textfield">
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit">
</label>
</p>
</form>';
?>
您需要在表单发送到的页面中运行该函数。
关于php - 如何在表单操作中执行 PHP 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/595358/