Jump to content

Problem on vadilate a webform..


moneytree
 Share

Recommended Posts

Hi everyone,I am new to javascript and written the following script for the purpose of validating my opt-in form.However,when I carried out a test by clicked on the submit button without filling in any field,to my suprise,it allowed for the submission without prompting any error message !Please kindly review the following script and advice the errors in it. --------------------------------------------------------------------------------------------------------------------------------------------<div id="formbox"><h3>Get Your Free Gifts !</h3><form METHOD="post" ACTION="http://moneymakeyourich.com/cgi-bin/formmail.pl"><input type=hidden name="recipient" value="moneytree@moneymakeyourich.com"><input type=hidden name="subject" value="Your Subject">First Name :<input type=text name="realname" size="20"><br>Last Name :<input type=text name="lastname" size="20"><br>Email           :<input type=text name="email" size="20"><br><input type="Submit" value="submit" onclick="verify()"/><script type="text/javascript"><!--function verify(){var first=document entry first_name value;var last=document entry last_name value;var email=document entry email_address value;var message="Please complete the following field(s): \n".var errors="".if(!first){errors+="First name\n";}if(!last){errors+="Last name\n";}if(!email){errors+="email address\n";}if(errors){alert(message+errors);}}//--></form><p><b>Important</b>:I will never share your information with anyone !</p>--------------------------------------------------------------------------------------------------------------------------------------------Thank you.Best regardsManicui

Link to comment
Share on other sites

Your code sure needs a lot of fixing up:

<div id="formbox"><h3>Get Your Free Gifts !</h3><form METHOD="post" ACTION="http://moneymakeyourich.com/cgi-bin/formmail.pl"><input type=hidden name="recipient" value="moneytree@moneymakeyourich.com"><input type=hidden name="subject" value="Your Subject">First Name :<input type="text" id="realname" name="realname" size="20"><br>Last Name :<input type="text" id="lastname" name="lastname" size="20"><br>Email           :<input type="text" id="email" name="email" size="20"><br><input type="Submit" value="submit" onsubmit="verify()"/><script type="text/javascript">function verify(){var first=document.getElementById("realname").value;var last=document.getElementById("lastname").value;var email=document.getElementById("email").value;var message="Please complete the following field(s): \n";var errors="";if(first.length == 0){errors+="First name\n";}if(last.length == 0){errors+="Last name\n";}if(email.length == 0){errors+="email address\n";}if(errors){alert(message+errors);return false;}}</script></form><p><b>Important</b>:I will never share your information with anyone !</p></div>

And I recommend you also validate the page on server-side later one, because the form can be sent if Javascript is disabled.

Link to comment
Share on other sites

Personally, I'd recommend you move everything inside the <script> tags to the <head> of your document(<script> tag included).You can copy and paste if you want. Make sure I didn't leave any typing mistakes in the code.

Link to comment
Share on other sites

Hi Ingolme,Many thanks for your replied to my quereis over webform issue.I had followed your advice to copied your suggested new code and paste it into my existing webform.However,it still allowed opt-in form submitted without fill in name and email address by click on the submit button.May I know what is the problem ?Please review my webform http://www.moneymakeyourich.com and test it yourself.Thank you.Best regardsManicui

Link to comment
Share on other sites

Hi Ingolme,It is really nice to have you in this forum to give your helping hand to newbie like me over their code issue.My webform is working finally with your helped ! Thank you.May I have a request from you ?What is the code to stop people from second subscription to the same offer on my site ?It will show the following error message when second subscription detected :-------------------------------------------------------------------------------------------------------------------------------------------- An Error Occurred Notice:Our records indicate that you are already subscribed to this list and have verified your subscription. --------------------------------------------------------------------------------------------------------------------------------------------Thank you.Best regardsManicui

Link to comment
Share on other sites

Hi Ingolme,It is really nice to have you in this forum to give your helping hand to newbie like me over their code issue.My webform is working finally with your helped ! Thank you.May I have a request from you ?What is the code to stop people from second subscription to the same offer on my site ?It will show the following error message when second subscription detected :-------------------------------------------------------------------------------------------------------------------------------------------- An Error Occurred Notice:Our records indicate that you are already subscribed to this list and have verified your subscription. --------------------------------------------------------------------------------------------------------------------------------------------Thank you.Best regardsManicui
You're going to need a server-side language for that.I can't tell you the exact script to use, but I'll explain what you have to do:In the page that the form information is sent to you have a script that will read the sent data (E-mail, for example) and check if it's already in the database (I'm supposing you're storing it in a database).You can use a query like this: "SELECT email FROM table WHERE email='' "And if it returns any results you can tell them that that E-mail is already registered.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...