不起作用,动态创建的提交中没有设置 post

huangapple go评论57阅读模式
英文:

Does not work isset post in dynamically created submit

问题

我有PHP文件中的代码:

<form id="form_id" action="" method="post">
<?php if (isset($_POST["123"])) {echo "BUTTON WORKS";}?>
</form>
<script src="file.js"></script>

我有JS文件中的代码:

let testButton = document.createElement("submit");
testButton.innerHTML = "Click it";
document.getElementById("form_id").appendChild(testButton);
testButton.name = "123";

PHP代码不起作用。为什么?

英文:

I have code in PHP file:

&lt;form id=&quot;form_id&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;?php if (isset($_POST[&quot;123&quot;])) {echo &quot;BUTTON WORKS&quot;;}?&gt;
&lt;/form&gt;
&lt;script src=&quot;file.js&quot;&gt;&lt;/script&gt;  

And I have code in JS file:

let testButton = document.createElement(&quot;submit&quot;);
testButton.innerHTML = &quot;Click it&quot;;
document.getElementById (&quot;form_id&quot;).appendChild(testButton);
testButton.name = &quot;123&quot;;

php code does not work. Why?

答案1

得分: 2

Create a button element not submit like this one

let testButton = document.createElement("button"); /HERE/
testButton.innerHTML = "Click it";
document.getElementById("form_id").appendChild(testButton);
testButton.name = "123";

英文:

Create a button element not submit like this one

 let testButton = document.createElement(&quot;button&quot;); /*HERE*/
testButton.innerHTML = &quot;Click it&quot;;
document.getElementById (&quot;form_id&quot;).appendChild(testButton);
testButton.name = &quot;123&quot;;

huangapple
  • 本文由 发表于 2023年6月12日 21:50:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定