Including the associated HTML and PHP form in a file – with Javascript submit ()

微信扫一扫,分享到朋友圈

Including the associated HTML and PHP form in a file – with Javascript submit ()

I was wondering how it might be possible to do this… I already know how to include the form and PHP in one file:

<form method="post"> <!-- might also loop back to the same HTML file with action-->
<?php
if (isset($_POST["sent"])) {
echo "<p>This string has been entered: " . $_POST["string"] . "</p><hr />";
}
?>
<p>Enter string:</p>
<p><input name="string" /></p>
<p><input type="submit" value="Submit String" name="sent"></p>
</form>

But if I am using Javascript to use custom triggers I need to do it like this:

<form action="phpfile.php" name="myForm" method="post">
<p>Enter Name: <input name="name" /></p>
</form>
<a href="https://www.tuicool.com/articles/NBV3MfR/javascript:document.myForm.submit();">Submit Name</a>

So there seems to be no way to reference any $_POST values I could use to check if they are already set… Is there a convenient solution to this?

You can check with request method is post, see example below:

if($_SERVER['REQUEST_METHOD'] == 'POST'){
echo "<p>This string has been entered: " . $_POST["string"] . "</p><hr />";
}

关厂后,特斯拉部分工人仍要上班完成汽车生产收尾

上一篇

健康码跨省互认按下快进键 一周内多个省份实现互认

下一篇

你也可能喜欢

Including the associated HTML and PHP form in a file – with Javascript submit &lpar;&rpar;

长按储存图像,分享给朋友