Php javascript submit()不工作
这是index.php中的表单——我试图通过单击嵌套在“a”锚中的图像以编程方式提交它:Php javascript submit()不工作,php,javascript,forms,form-submit,Php,Javascript,Forms,Form Submit,这是index.php中的表单——我试图通过单击嵌套在“a”锚中的图像以编程方式提交它: <form name="landingForm" id="landingFormId" method="post" action="index.php"> <input type="text" size="250" maxlength="250" id="artifactName">Enter an artifact na
<form name="landingForm" id="landingFormId" method="post" action="index.php">
<input type="text" size="250" maxlength="250"
id="artifactName">Enter an artifact name here...
</input>
<a href="javascript:document.landingForm.submit()">
<img src="http://localhost/myProj/bronzeAgeCaveDrawing.jpg"
alt="Submit this form" name="imageFormSubmitter" />
</a>
</form>
对于这一点,我甚至不确定上面的PHP代码是否会被调用
<a href="javascript:document.landingForm.submit()">
外卖:
1) the syntax "document.landingForm.submit()" is 100% fine.
2) the 'name' attribute of my <img> tag does NOT get posted (not sure why,
but it's not the worst thing happening for me right now so I'll deal with it)
3) giving the text <input> field a 'name' attribute made its way fine to the POST array.
4) the call to submit() does in fact pay attention to the method="post" in my
form declaration.
1)语法“document.landingForm.submit()”是100%正确的。
2) 我的标签的“name”属性未发布(不确定原因,
但这对我来说并不是最糟糕的事情,所以我会处理的)
3) 为文本字段指定一个“name”属性可以很好地处理POST数组。
4) 对submit()的调用实际上注意到了我的
形式声明。
我带着它跑,谢谢大家。对于我来说,有不止一个同样可以接受的答案,所以我将+1你们所有人
那就得选一个。再次感谢。您没有在
标签上设置名称属性和
资料来源:
另外请注意,HTML5中的
标记没有/不能有孩子。我没有阅读您的完整文章,但有一点建议-尝试使用
而不是使用链接和图像。您不应该使用document.getElementById('landingForm')。submit()如果我不能让它工作,我会尝试使用type='image',但是--我看到太多不同的帖子使用了完全相同的anchor+image+submit()技术。当然,并不是所有的海报都是凭空制作出来的,这些海报中的一些一定是真的起作用了!你可以使用anchor+image技术,它会起作用的。但是您不会在帖子内容中看到来自图像的名称
值。相反,您将只看到任何
元素的值。@WANT最佳–外卖(2)是因为只有
元素参与表单内容(好的,
,
,
,,
,…)在我的帖子底部看到我的更新,我是如何接受你们的建议并使这一条得以实施的——谢谢。感谢那条狗,我一直在使用w3schools.com,哇,这条狗太棒了,它现在是我的参考,谢谢dave@wantTheBest:是的,好多了(几乎没有广告!)
<a href="javascript:document.landingForm.submit()">
<form name="landingForm" id="landingFormId" method="post" action="index.php">
<input type="text" size="250" maxlength="250" name="itemName_name"
id="artifactName">Enter an artifact name here...
</input>
<a href="javascript: document.landingForm.submit()">
<img src="http://localhost/myProj/bronzeAgeCaveDrawing.jpg"
alt="Submit this form" name="imageFormSubmitter" />
</a>
</form>
if(isset( $_POST['itemName_name']))
{
showAlertBox("The index page form 'landingForm' was just submitted.");
var_dump($_POST);
}
array
'itemName_name' => string 'fffffffffff' (length=11)
1) the syntax "document.landingForm.submit()" is 100% fine.
2) the 'name' attribute of my <img> tag does NOT get posted (not sure why,
but it's not the worst thing happening for me right now so I'll deal with it)
3) giving the text <input> field a 'name' attribute made its way fine to the POST array.
4) the call to submit() does in fact pay attention to the method="post" in my
form declaration.
<form name="landingForm" id="landingFormId" method="post" action="index.php">
<input type="text" size="250" maxlength="250" name="artifactName"
id="artifactName" />Enter an artifact name here...
<input type="image" src="http://localhost/myProj/bronzeAgeCaveDrawing.jpg"
alt="Submit this form" name="imageFormSubmitter" />
</form>