通过Javascript提交表单,该表单在外部PHP文件中定义

通过Javascript提交表单,该表单在外部PHP文件中定义

问题描述:

我有一个通过php注入页面主体的表单.我有一个触发javascript验证功能的按钮,最后它应该提交表单,但似乎不想提交.

I have a form which is injected into the page body via php. I have a button which triggers a javascript validation function, and at the end it should submit the form but it doesn't seem to want to submit.

我正在使用函数调用:

document.myform.submit();

该脚本肯定到达了此函数调用,因为我成功弹出了一条debug alert()消息.它位于在jQuery $(document).ready()函数之后定义的validate& submit函数中.

The script definitely reaches this function call, as I have a debug alert() message pop up successfully. Its located in a validate&submit function which is defined after a jquery $(document).ready() function.

我检查了所有明显的问题,例如正确打开/关闭了表单标签,表单名称正确等,但是我似乎无法解决问题.

I've checked all the obvious things like form tags opened/closed properly, form name correct etc but I can't seem to work out the problem.

有什么想法吗?我还没有提交整个文件,因为文件杂乱无章,但是我可以根据需要提交.

Any ideas? I haven't submitted the whole file as its cluttered with other stuff, but I can if needed.

非常感谢, 奥利弗(Oliver)

Many Thanks, Oliver

在php完成其操作后,在这里找到html源: http://pastebin.com/2EaucEar >

Heres the html source after php has done its thing: http://pastebin.com/2EaucEar

找到了!

我正在使用一个看起来像普通链接的按钮,但没有使用任何按钮功能.因此,它也可能是一个链接.按钮的名称是 name ='submit'对我来说很有意义,但是我通过设置 type ='button'来确保它不是提交按钮. >.

I'm using a button which is made to look like a normal link, but not using any of the button features. So it might as well be a link. The name of the button was name='submit' which made perfect sense to me, but I made sure it wasn't a submit button by setting the type='button'.

似乎Submit是一个关键字,并将按钮转换为Submit或其他内容.不能完全确定,但是将按钮名称(我在其余代码中没有提到)更改为其他名称可以解决此问题.

It seems submit is a keyword, and cast the button as a submit or something. Not entirely sure, but changing the button name (which I don't refer to in the rest of the code) to something else fixed the problem.

感谢您的帮助.您帮助我缩小了范围.

Thanks for your help guys. You helped me narrow it down.