admin管理员组文章数量:1426227
Is it possible to to submit an HTML Form (with a PHP action) and include a javascript
onsubmit="VerifyFields()
?
I am trying to do it now, but it seems that it will do the PHP action and not do the onsubmit
.
Update:
Thanks for all of your help.
The problem was that I was putting my VerifyMe()
function in the <head></head>
, as opposed to the <body></body>
.
Is it possible to to submit an HTML Form (with a PHP action) and include a javascript
onsubmit="VerifyFields()
?
I am trying to do it now, but it seems that it will do the PHP action and not do the onsubmit
.
Update:
Thanks for all of your help.
The problem was that I was putting my VerifyMe()
function in the <head></head>
, as opposed to the <body></body>
.
- 1 Should be. Can you post some code? – Jeff B Commented Feb 11, 2010 at 23:39
3 Answers
Reset to default 6If return false in the onsubmit handler, the form will not submit, if you return true, it will.
You should make the function VerifyFields return true or false, and call it like this:
onsubmit="return VerifyFields();"
<script type="text/javascript">
function validateForm(){
...
}
</script>
<form name="contact" action="<?=$_SERVER['PHP_SELF']?>"
method="post" onsubmit="return validateForm();">
<label> Foo </label>
<input type="text" class="txt_input" name="sender_name" />
...
<input type="image" src="img/send.jpg" id="submitButton"
name="submitForm" value="send" />
</form>
I would test the inputs bevor submitting any fields to the server. I would test it client side by javascript and finaly send it to the server. You could call Your script also this way.
<input type="text" class="txt_input" name="sender_name" onchange="validateForm();" />
本文标签: Including JavaScript validation in a form submit in PHPStack Overflow
版权声明:本文标题:Including JavaScript validation in a form submit in PHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745471651a2659777.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论