andy pollina
asked on
check button value before submit
Hi, my web site has a request information form page which uses formmail.pl. Lately I've been receiving a lot of robot generated emails from the page so I decided to put a option box on the page whereby if the option "Human" is not selected, then no email will be sent through the formmail.pl file.
I've not too experienced with this and I've not worked with JavaScript for a long time, thus I can't get my idea to work.
On the page is a form which I've described as below:
<form name="infoRequest" enctype="application/x-www -form-urle ncoded">
<input name="subject" type="hidden" value="Information Request">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
I then put in a select option box for a visitor to select a value from the list:
<tr>
<td height="30" width="33%">what am I:</td>
<td textarea rows="3" cols="30" height="30" width="67%"</TD>
<select name="robotyn" onchange="checkrobot();" id="dropDown1">
<option value="Robot">I'm a Robot</option>
<option value="Human">I'm a human</option>
<option value="other">Other</optio n>
</select>
</tr>
below that is the submit and reset buttons. My intension is for a script to be run when the submit button is checked.
<tr>
<td colspan="2" width="100%" align="center">
<input TYPE="submit" NAME="Submit" VALUE="Submit" onclick="(function() {checkrobot();return false;})()"><input TYPE="reset" VALUE="Reset">
</td>
</tr>
here is the script:
function checkrobot(){
a = document.getElementById("d ropDown1") ;
if(a.value == "Human")
window.open('file://"../cg i-bin/form mail.pl"') ;
return true;
else
window.location.reload();
document.getElementById("s ubmit").re set();
return false;
}
</script>
What I'm trying to accomplish in the script is for it to check if the option "Human" was selected, if so - to open the formmail.pl file which will send an email containing the other form elements.
If "Human" is not selected, then to reset the form and start over again.
The script seems to be working if other than the option "Human" is selected but it is not opening the formmail,pl file if "Human" is selected.
I've attached the entire htm file. Hopefully an expert can help me with solving this issue.
Your assistance is appreciated.
I've not too experienced with this and I've not worked with JavaScript for a long time, thus I can't get my idea to work.
On the page is a form which I've described as below:
<form name="infoRequest" enctype="application/x-www
<input name="subject" type="hidden" value="Information Request">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
I then put in a select option box for a visitor to select a value from the list:
<tr>
<td height="30" width="33%">what am I:</td>
<td textarea rows="3" cols="30" height="30" width="67%"</TD>
<select name="robotyn" onchange="checkrobot();" id="dropDown1">
<option value="Robot">I'm a Robot</option>
<option value="Human">I'm a human</option>
<option value="other">Other</optio
</select>
</tr>
below that is the submit and reset buttons. My intension is for a script to be run when the submit button is checked.
<tr>
<td colspan="2" width="100%" align="center">
<input TYPE="submit" NAME="Submit" VALUE="Submit" onclick="(function() {checkrobot();return false;})()"><input TYPE="reset" VALUE="Reset">
</td>
</tr>
here is the script:
function checkrobot(){
a = document.getElementById("d
if(a.value == "Human")
window.open('file://"../cg
return true;
else
window.location.reload();
document.getElementById("s
return false;
}
</script>
What I'm trying to accomplish in the script is for it to check if the option "Human" was selected, if so - to open the formmail.pl file which will send an email containing the other form elements.
If "Human" is not selected, then to reset the form and start over again.
The script seems to be working if other than the option "Human" is selected but it is not opening the formmail,pl file if "Human" is selected.
I've attached the entire htm file. Hopefully an expert can help me with solving this issue.
Your assistance is appreciated.
Hello
it's better to use google reCaptcha to test if it's a human or a robot it's more secure
https://www.google.com/recaptcha/intro/v3beta.html
it's better to use google reCaptcha to test if it's a human or a robot it's more secure
https://www.google.com/recaptcha/intro/v3beta.html
+1 for Google reCaptcha - that's generally the way most forms are validated against autobots these days. It's what people are used to and is much harder to by-pass than your current implementation.
ASKER
Hi Chris,
Yes, very old school. Thanks for offering your support.
Excuse my ignorance. So are there 2 form lines or is that just 1 line with the :
<form action="../some/path/formm ail.pl" method="post" onsubmit="return checkrobot(e);">
I tried both ways and getting the same result - the formmail.pl file executes regardless of what is chosen.
Yes, very old school. Thanks for offering your support.
Excuse my ignorance. So are there 2 form lines or is that just 1 line with the :
<form action="../some/path/formm
I tried both ways and getting the same result - the formmail.pl file executes regardless of what is chosen.
Google Recaptcha is just what i'd use
ASKER
will give that a look and try now!
Thanks!!
Thanks!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris, it wouldn't work with the method=get changed it to post and Whalla!
Thanks!!
Thanks!!
<form action="../some/path/formm
Then you would bind your function to the onsubmit() of the form, so:
<form action="../some/path/formm
And now your script should return true or false. It's not very robust, but something like this.
Open in new window