Help Needed with forms |
Help Needed with forms |
mitch1221 |
Jul 11 2008, 02:59 AM
Post
#1
|
Group: Members Posts: 1 Joined: 11-July 08 Member No.: 6,138 |
Hi
I need some help. i have been trying for a few days to get a form submitted and all values valadated in the form and then after clicking submit and values are checked to redirect to another webpage. My code for the page is shown below: <script type="text/javascript"><!-- hide from old browsers function validate (form) { var alertstr = ''; var invalid = 0; var invalid_fields = new Array(); // first_name: standard text, hidden, password, or textarea box var first_name = form.elements['first_name'].value; if (first_name == null || first_name === "") { alertstr += '- Invalid entry for the "First Name" field\n'; invalid++; invalid_fields.push('first_name'); } // last_name: standard text, hidden, password, or textarea box var last_name = form.elements['last_name'].value; if (last_name == null || last_name === "") { alertstr += '- Invalid entry for the "Last Name" field\n'; invalid++; invalid_fields.push('last_name'); } // email: standard text, hidden, password, or textarea box var email = form.elements['email'].value; if (email == null || ! email.match(/^[\w\-\+\._]+\@[a-zA-Z0-9][-a-zA-Z0-9\.]*\.[a-zA-Z]+$/)) { alertstr += '- Invalid entry for the "Email" field\n'; invalid++; invalid_fields.push('email'); } // phone: standard text, hidden, password, or textarea box var phone = form.elements['phone'].value; if (phone == null || ! phone.match(/^\d{5}\-\d{6}$|^\d{3}\-\d{4}\-\d{4}$|^\d{11}$|^\d{5}\ \d{6}$|^\d{3}\ \d{4}\ \d{4}$|^\d{4}\-\d{7}$/)) { alertstr += '- Invalid entry for the "Phone" field\n'; invalid++; invalid_fields.push('phone'); } // mailing_list: radio group or multiple checkboxes var mailing_list = null; var selected_mailing_list = 0; for (var loop = 0; loop < form.elements['mailing_list'].length; loop++) { if (form.elements['mailing_list'][loop].checked) { mailing_list = form.elements['mailing_list'][loop].value; selected_mailing_list++; if (mailing_list == null || mailing_list === "") { alertstr += '- Choose one of the "Mailing List" options\n'; invalid++; invalid_fields.push('mailing_list'); } } // if } // for mailing_list if (! selected_mailing_list) { alertstr += '- Choose one of the "Mailing List" options\n'; invalid++; } if (invalid > 0 || alertstr != '') { if (! invalid) invalid = 'The following'; // catch for programmer error alert(''+invalid+' error(s) were encountered with your submission:'+'\n\n' +alertstr+'\n'+'Please correct these fields and try again.'); return false; } return true; // all checked ok } function clear_form() { document.execute.reset(); } function submitForm(s) { s.value = " Uploading Information "; return true; } //--> </script> </head> <body bgcolor="white"> <table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="100%" height="100" align="center" class="longtitles" >Contact us</td> </tr> </table> <!-- Generated by CGI::FormBuilder v3.0501 available from www.formbuilder.org --> <Form name="execute" enctype="multipart/form-data" action="mailto:info@tropicalsdirect.co.uk" method="post" onsubmit="return validate(this) && setTimeout('clear_form()', 300); return true;"> <div><input id="_submitted" name="_submitted" type="hidden" value="1" /></div> <table align="center"> <tr valign="top"> <td><b>Business Name</b></td> <td><input name="business_name" type="text" /></td> </tr> <tr valign="top"> <td><b>First Name</b></td> <td><input id="first_name" name="first_name" type="text" /></td> </tr> <tr valign="top"> <td><b>Last Name</b></td> <td><input id="last_name" name="last_name" type="text" /></td> </tr> <tr valign="top"> <td><b>Email</b></td> <td><input id="email" name="email" type="text" /></td> </tr> <tr valign="top"> <td><b>Phone</b></td> <td><input id="phone" name="phone" type="text" /></td> </tr> <tr> <td><b>Customer Type</b></td> <td><select name="customer type"><option>Please Select...</option><option>Florist</option><option>Wholesale</option><option>Retail</option><option>General Public</option></select></td> </tr> <tr valign="top"> <td align="right" bgcolor="#FFFFFF"> <p>Comments</p> </td> <td align="left"> <textarea name="comment" cols="50" rows="10"></textarea> </td> </tr> <tr valign="top"> <td><b>Mailing List</b></td> <td><input id="mailing_list_Subscribe" name="mailing_list" type="radio" value="Subscribe" /> <label for="mailing_list_Subscribe">Subscribe</label> <input id="mailing_list_Unsubscribe" name="mailing_list" type="radio" value="Unsubscribe" /> <label for="mailing_list_Unsubscribe">Unsubscribe</label> </td> </tr> <tr valign="top"> <td align="center" colspan="2"><input id="_submit" name="_submit" type="submit" value="Submit"/><input TYPE="reset" NAME="Clear" VALUE="Clear Form and Start Over"></td> </tr> </table> </form> </div> <table align="center"> <tr> <td width="506"> <p align="center" class="smalltitles">Head Office Address:<br> Tropicals Direct Ltd<br>41 Longford Close<br>Hampton Hill<br>Middlesex<br>TW12 1AD</p> </td> <td width="353"> <p align="center" class="smalltitles">TRADE OUTLET:<br> wholesale Nurseries<br> Spout Lane<br> Stanwell Moor<br> Middlesex<br> TW19 6BN</p> </td> </tr> <tr> <td colspan="2"><br><br><p align="center" class="smalltitles">Telephone Number: +44 (0)20 8941-1117</p> <p align="center" class="smalltitles">Fax Number: +44 (0)20 8941-8777</p> <p align="center" class="cominfo">Email address: <a href="mailto:info.tropicalsdirect@btconnect.com" class="weblinks">info@tropicalsdirect.co.uk</a></p> </td> </tr> </table> </body> </html> Thanks in advance to anyone who can help. Mitch |
Brian Chandler |
Jul 11 2008, 03:59 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Please give the URL of the actual page.
But as long as you are using action="mailto:.. you're not really going to get what you want. See the FAQ on using forms. |
Darin McGrew |
Jul 11 2008, 04:01 AM
Post
#3
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
Forms using action="mailto:..." are unreliable on the WWW. See the FAQ entry How do I get form data emailed to me?
|
Lo-Fi Version | Time is now: 26th April 2024 - 03:45 PM |