Jump to content

My written script failed to validate my opt-in form,please advice,thanks.


moneytree

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 regards

Manicui

 

Link to comment
Share on other sites

here you go:

 

<script language="javascript">

function verify()
{
var first = document.myform.realname.value;
var last = document.myform.lastname.value;
var email = document.myform.email.value;

var errors1 = "";
var errors2 = "";
var errors3 = "";
var message="Please complete the following field(s): \n";

if (first.length == "0") {
errors1="First name\n";
}
if (last.length == "0") {
errors2="Last name\n";
}
if (email.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform.submit();
}
}
</script>

<div id="formbox">
<h3>Get Your Free Gifts !</h3>
<form name="myform" 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">


Last Name :
<input type=text name="lastname" size="20">


Email           :
<input type=text name="email" size="20">


<input type="button" value="submit" onclick="verify()"/>

</form>
<p>Important:I will never share your information with anyone !</p>

 

there's other ways to validate your form fields besides this; with more complex validation (like regex for email address fields), but this should work fine for basic validation.

Link to comment
Share on other sites

Hi phpQuestioner,

 

Good day to you.

 

It is really nice to hear from you again to replied to my queries.

 

I had followed your advice to insert the script into my site and tried to test it by without filled in any data into the opt-in form,however,it allowed for submission after I clicked the submit button.

 

Please kindly review and advcie on the issue and visit my site :www.moneymakeyourich.com for comments.

 

Thank you.

 

Best regards

manicui

Link to comment
Share on other sites

Hi PhpQuestioner,

 

Good day to you.

 

I had followed your advice and copied the code suggested by to into my site,however,it allowed opt-in to be submitted without filled in the opt-in form.

 

Please view it www.moneymakeyourich.com and advice the problem.

 

Thank you.

 

Best regards

Manicui

 

Link to comment
Share on other sites

Hi PhpQuestioner,

 

My webform is working finally with your suggested code ! Thank you !

 

I am glad to have you in this forum to give your helping hand to newbie like me and others.

 

May I have any other request from you ?

 

How to add a code based on my existing webform code to stop people from second subscription to the same offer ?

 

It will show the following error message :

 

----------------------------------------------------------------------------------------------------

 

An Error Occurred

 

Notice:

Our records indicate that you are already subscribed to this list and have verified your subscription.

 

----------------------------------------------------------------------------------------------------

 

Thank you.

 

best regards

Manicui

 

 

Link to comment
Share on other sites

 

The best way to do this is probably server side; using a database. An alternate; client side idea, would be to create a cookie and check for the cookie. If the cookie exist, don't display the form; otherwise display the form. The draw back to that is that someone could just erase their cookies; so that is why I said server side with a database would be the best we to do this.

Link to comment
Share on other sites

  • 2 weeks later...

Hi phpQuestioner,

 

Good day to you.

 

I had bought this " drop in ads " software to add it into my site to increase and build up my opt-in list.

 

The webform on my site is working perfectly with your helped.To add this " drop in ads " into my site is simply highlight my webform in IE7,copy and paste it into my index.php.

 

After copied it into my site,I had tried to entered name,email address into the " drop in ads " webform,but,it failed to work !

 

Please kindly visit my site http://www.moneymakeyourich.com and advice what's wrong with it.

 

Many thanks for your effort and look forward to hear from you soon.

 

Thank you.

 

Best regards

Manicui

Link to comment
Share on other sites

 

Issue

 

1.) Your not using the <form></form> tags around the form that is in your drop box advertisement.

2.) You cannot have two forms with the same name and same field names and expect the javascript to submit them both.

 

Solution:

 

1.) Make sure you wrap the drop box advertisement form with the proper form tags.

2.) Give your drop box advertisement form another name; such as "mysecondform" and then I would give my form field a different name to; such as: realname2, lastname2, and email2 (this will help you and the JavaScripts interaction with the browser avoid confusion). Then add this JavaScript with the previous script that I already wrote for you.

 

function verify()
{
var first2 = document.mysecondform.realname2.value;
var last2 = document.mysecondform.lastname2.value;
var emailtwo = document.mysecondform.email2.value;

var errors1 = "";
var errors2 = "";
var errors3 = "";
var message="Please complete the following field(s): \n";

if (first2.length == "0") {
errors1="First name\n";
}
if (last2.length == "0") {
errors2="Last name\n";
}
if (emailtwo.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform2.submit();
}
}

 

Also; you really should not demand that users join a opt-in-list, because allot of people don't want to be required to do so; too continue viewing your website - you know what I mean. ;)

Link to comment
Share on other sites

Hi phpQuestioner,

 

Good day to you.

 

Many thanks for your replied to my queries of webform issue.

 

I had tried to understand your advice and made changes on drop box advertisement,however,it may due to my little understanding of the javascript and webform's function,after removing some code,both of the webform on my site and drop box advertisement failed to work.

 

Please kindly visit my site www.moneymakeyourich.com and advice what's wrong with it.

 

 

Thanks you.

 

Best regards

Manicui

 

 

Link to comment
Share on other sites

 

Sorry; Moneytree - My fault; rename you second function - like have a verify() and a verify2() function. See if that corrects the issue; I think it should, but if it does not - try renaming you error1, error2, and error3 variables in the second function - in the verify2() function - you could change them to something like error1a, error2a, and error3a - but I don't think you will have to do that.

 

try this

 

<script language="javascript">

var errors1 = "";
var errors2 = "";
var errors3 = "";
var message="Please complete the following field(s): \n";

function verify()
{
var first = document.myform.realname.value;
var last = document.myform.lastname.value;
var email = document.myform.email.value;

if (first.length == "0") {
errors1="First name\n";
}
if (last.length == "0") {
errors2="Last name\n";
}
if (email.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform.submit();
}
}

function verify2()
{
var first2 = document.mysecondform.realname2.value;
var last2 = document.mysecondform.lastname2.value;
var emailtwo = document.mysecondform.email2.value;

if (first2.length == "0") {
errors1="First name\n";
}
if (last2.length == "0") {
errors2="Last name\n";
}
if (emailtwo.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform2.submit();
}
}

</script>

Link to comment
Share on other sites

Hi phpQuestioner,

 

Good day to you.

 

I am sorry to post it agian to you for my drop box advertisement issue.

 

I had followed your advice and made the necessary changes without " a " for error1,error2 and error3 in verify2 (),but,it didn't wrok.Therefore,I added " a " and made the changes to error1a,error2a and error3a,it failed to work too.

 

Please review and advice it at www.moneymakeyourich.com

 

Thanks for your time and effort in helping me on this issue.

 

Thank you.

 

Best regards

Manicui

 

 

Link to comment
Share on other sites

 

OK moneytree; this will work - I tested it, so I know it will. You will use the complete JavaScript below and you would just rename your forms - the form in the page would be "myform" and the form in the ad would be "myform2". Hope this finally solves your problem - Good Luck. ;)

 

<script language="javascript">

function verify()
{

var errors1 = "";
var errors2 = "";
var errors3 = "";
var message="Please complete the following field(s): \n";

var first = document.myform.realname.value;
var last = document.myform.lastname.value;
var email = document.myform.email.value;

if (first.length == "0") {
errors1="First name\n";
}
if (last.length == "0") {
errors2="Last name\n";
}
if (email.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform.submit();
}
}


function verify2()
{

var errors1 = "";
var errors2 = "";
var errors3 = "";
var message="Please complete the following field(s): \n";

var first = document.myform2.realname.value;
var last = document.myform2.lastname.value;
var email = document.myform2.email.value;

if (first.length == "0") {
errors1="First name\n";
}
if (last.length == "0") {
errors2="Last name\n";
}
if (email.length == "0") {
errors3="email address\n";
}
if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") {
alert(message + "\n\n" + errors1 + errors2 + errors3);
}
else {
document.myform2.submit();
}
}

</script>

</head>

<body>


<!-- First Form -->

<form name="myform" 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">


Last Name :
<input type=text name="lastname" size="20">


Email           :
<input type=text name="email" size="20">


<input type="button" value="submit" onclick="verify()"/>

</form>
<p>Important:I will never share your information with anyone !</p>


<BR><BR><!-- REMOVE THESE LINE BREAKS - FOR DEMO ONLY --><BR><BR>


<!-- Second Form -->

<form name="myform2" 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">


Last Name :
<input type=text name="lastname" size="20">


Email           :
<input type=text name="email" size="20">


<input type="button" value="submit" onclick="verify2()"/>

</form>
<p>Important:I will never share your information with anyone !</p>

Link to comment
Share on other sites

Hi phpQuestioner,

 

Good day to you.

 

I wanted to say a " BIG THANK YOU " to you for your advice over webform issues ! Both of the webform on my site and drop box advertisement are working now ! 

 

Many thanks for your time and effort,it really shorten my time to get it fixed with your advice and helped !

 

Thank you.

 

Good night.

 

Best regartds

Manicui

Link to comment
Share on other sites

Hi phpQuestioner,

 

Good day to you.

 

I am sorry to post you again regarding my webform issue.

 

Infact,after followed your advice,both of the webform on my site  and  drop box advertisement are working perfectly.At this moment,the drop box advertisement work fine with only first name,last name and email address.

 

However,the drop box advertisement need to add promotion's text to let subscriber know what is all about with this top-in.When I added some promotion's text like - " Special Report * "Leading Internet expert reveals proven strategies for starting your own Internet business!" ,it failed to work. I don't know,it may due to my carelessness to delete some of the code.

 

I had tried to made some changes in index.php file,it became worst with duplication on my first opt-in form ( Now,it had two FREE SEO EBOOK on my site ).

 

I am sorry for creating such a mess in index.php file and looking for your advice and assistance for removing the duplication on my first opt-in form and making the drop box advertisement work again.

 

Please kindly review and advice it at www.moneymakeyourich.com .

 

Thank you.

 

Best regards

Manicui

 

 

 

 

 

Link to comment
Share on other sites

 

What did you do; try to display your promo info with JavaScript and altered the original code?

 

My advice; is for you to take the last code I created for you and use it. Remove what ever you have in your page; that is similar to what I posted for you and copy/paste original code (from above - my original code) into you index page.

 

Tell me how you want to display your promo info and I will incorporate this with your current code.

Link to comment
Share on other sites

Hi phpQuestioner,

 

Many thanks for your prompt replied to my queries of webform issue.

 

First of all,I would like to let you have a clear picture of the Drop box advertisement.It has a editor to allow changes on the type of promotion I want.Therefore,I am able to change the " promo info " as and when I like depending on what type of product and service I am promoting during that time.

 

To create a new Drop box advertisement for new promotion,I need to go to its editor to enter whatever

" promo info ",after that,I need a working webform which can be seen in IE7 ( not its html code ) with first name,last name,email address and the submit button.I just highlight these info,copy and paste it right below the " promo info " I'd just created in editor,follow by copy the whole drop box advertisement into my webpage - index.php,that's all.

 

Therefore,if I need to change whatever " promo info ", I just make the changes in its editor,but,need to copy and paste with a working webform below it.This working webform must be the webform on the drop box advertisement you had created for me.

 

I hope you don't mind taking your time for my explanation to you on Drop box advertisement.

 

I had break and copied your suggested code into two part due to few row of text stand between them.Therefore,I didn't copy the entire code into my webpage,but,serperate them with form1 above these text and form2 below it.By the way,do I need to copy </head> and </body> in your suggested code ? It's in betwwen the form1 and form2.

 

Please visit my site and you'll know what I meant : www.moneymakeyourich.com

 

Now,my main concern is to remove the duplication on my first opt-in form ( Now,it had two FREE SEO EBOOK on my site ),follow by making the Drop box advertisement's webform work.

 

This's just my idea to fix these two problem.I do understand that it's easier said than done and forgive me if I am asking too much from you.

 

Thank you and have a nice day.

 

Best regards

Manicui

 

   

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.