...

View Full Version : Newbie Help! Redirect After Submit on Form with validation



Wileemarie
07-10-2007, 09:31 PM
Hi! I'm new to .php and trying to work with what the people before me set up - working in Dreamweaver.
I have a simple form and here is what I want to happen: Hit submit> validate> send you back to the page if not correct or submit info> THEN redirect to another page. The validation and submit (submits through mail program) work but I can't get the redirect to work or if the redirect works then the submit doesn't. How do I get both to work on the one submit button? Please Help!!! :eek: THANKS! Here is my page:


<?php
$pageTitle = 'Speed Global Services Preference Form';
include('header.php');
include('sidebar.php');
?>
<style type="text/css">
<!--
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 16px;
}
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 10px; }
.style11 {font-size: 16}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<p align="center" class="style2 style2"><br />
<span class="style11">Preference/Accounts Payable <br />
Contact Information Form</span><br />
<br />
<input type="hidden" name="subject" value="Preferences Form" />
<form action="mailto:dgenco@speedgs.com" method="POST" enctype="text/plain">
<span class="style7">* Denotes required fields.</span> <br />
<table width="498" border="0">
<tr>
<td width="112" align="left" class="style7">
<label>Company Name * </label> </td>
<td width="376" align="left"><label>
<input name="Company Name:" type="text" id="Company Name:" size="50" />
</label></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Accounts Payable Primary Contact</label>
*</td>
<td align="left"><input name="Contact:" type="text" id="Contact:" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Email Address </label>
*</td>
<td align="left"><input name="Email:" type="text" id="Email:" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Billing Address </label>
*</td>
<td align="left"><input name="Phone#" type="text" id="Billing Address" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7"><label>Phone Number </label>
*</td>
<td align="left"><input name="Phone#" type="text" id="Phone#" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7"><label>Fax Number* </label>
</td>
<td align="left"><input name="Fax #:" type="text" id="Fax #:" size="50" /></td>
</tr>
</table>
<br />
<table width="498" border="0">
<tr>
<td width="112" align="left" class="style7"><label>I prefer to receive
my invoices via </label></td>
<td width="376" align="left"><label></label>
<span class="style7">
<input name="Invoices via regular mail?" type="checkbox" id="Invoices via regular mail?" value="Yes" />
U.S. Postal Service </span><br />
<label>
<input name="Invoices via email" type="checkbox" id="Invoices via email" value="Yes" />
</label>
<span class="style7">Email</span></td>
</tr>
<tr>
<td align="left" class="style7"><label>I prefer to receive my statements
via </label></td>
<td align="left"><label></label>
<span class="style7">
<input name="Statments via Regular Mail?" type="checkbox" id="Statments via Regular Mail?" value="Yes" />
U.S. Postal Service </span><br />
<label>
<input name="Statements via Email" type="checkbox" id="Statements via Email" value="Yes" />
</label>
<span class="style7">Email</span></td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left">&nbsp;</td>
</tr>
<tr>
<td align="left" class="style7">Notes/Special Instructions </td>
<td align="left"><textarea name="Notes/Special Instructions:" cols="50" rows="10" id="Notes/Special Instructions:"></textarea></td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left">&nbsp;</td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left"><input name="Reset Form" type="reset" id="Reset Form" value="Reset Form" />
<br />
<label>
<input name="Submit" type="submit" onclick="MM_validateForm('Company Name:','','R','Contact:','','R','Email:','','RisEmail','Billing Address','','R','Phone#','','R','Fax #:','','R');return document.MM_returnValue" value="Submit" />
</label> </td>
</tr>
</table>
<p align="left"><label></label>
</p>
</form>
<p>&nbsp;</p>

<?php include('footer.php'); ?>

rafiki
07-10-2007, 11:08 PM
<?php
$pageTitle = 'Speed Global Services Preference Form';
include('header.php');
include('sidebar.php');
?>
<style type="text/css">
<!--
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 16px;
}
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 10px; }
.style11 {font-size: 16}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<p align="center" class="style2 style2"><br />
<span class="style11">Preference/Accounts Payable <br />
Contact Information Form</span><br />
<br />
<input type="hidden" name="subject" value="Preferences Form" />
<form action="mailto:dgenco@speedgs.com" method="POST" enctype="text/plain">
<span class="style7">* Denotes required fields.</span> <br />
<table width="498" border="0">
<tr>
<td width="112" align="left" class="style7">
<label>Company Name * </label> </td>
<td width="376" align="left"><label>
<input name="Company Name:" type="text" id="Company Name:" size="50" />
</label></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Accounts Payable Primary Contact</label>
*</td>
<td align="left"><input name="Contact:" type="text" id="Contact:" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Email Address </label>
*</td>
<td align="left"><input name="Email:" type="text" id="Email:" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7">
<label>Billing Address </label>
*</td>
<td align="left"><input name="Phone#" type="text" id="Billing Address" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7"><label>Phone Number </label>
*</td>
<td align="left"><input name="Phone#" type="text" id="Phone#" size="50" /></td>
</tr>
<tr>
<td align="left" class="style7"><label>Fax Number* </label>
</td>
<td align="left"><input name="Fax #:" type="text" id="Fax #:" size="50" /></td>
</tr>
</table>
<br />
<table width="498" border="0">
<tr>
<td width="112" align="left" class="style7"><label>I prefer to receive
my invoices via </label></td>
<td width="376" align="left"><label></label>
<span class="style7">
<input name="Invoices via regular mail?" type="checkbox" id="Invoices via regular mail?" value="Yes" />
U.S. Postal Service </span><br />
<label>
<input name="Invoices via email" type="checkbox" id="Invoices via email" value="Yes" />
</label>
<span class="style7">Email</span></td>
</tr>
<tr>
<td align="left" class="style7"><label>I prefer to receive my statements
via </label></td>
<td align="left"><label></label>
<span class="style7">
<input name="Statments via Regular Mail?" type="checkbox" id="Statments via Regular Mail?" value="Yes" />
U.S. Postal Service </span><br />
<label>
<input name="Statements via Email" type="checkbox" id="Statements via Email" value="Yes" />
</label>
<span class="style7">Email</span></td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left">&nbsp;</td>
</tr>
<tr>
<td align="left" class="style7">Notes/Special Instructions </td>
<td align="left"><textarea name="Notes/Special Instructions:" cols="50" rows="10" id="Notes/Special Instructions:"></textarea></td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left">&nbsp;</td>
</tr>
<tr>
<td align="left" class="style7">&nbsp;</td>
<td align="left"><input name="Reset Form" type="reset" id="Reset Form" value="Reset Form" />
<br />
<label>
<input name="Submit" type="submit" onclick="MM_validateForm('Company Name:','','R','Contact:','','R','Email:','','RisEmail','Billing Address','','R','Phone#','','R','Fax #:','','R');return document.MM_returnValue" value="Submit" />
</label> </td>
</tr>
</table>
<p align="left"><label></label>
</p>
</form>
<p>&nbsp;</p>

<?php include('footer.php'); ?>
it helps us read the code...
and isn't this a javascript problem?

meth
07-11-2007, 12:14 AM
This webform is lazy coding. It will not work reliably for all visitors. It's functionality depends on whether they have a mail client installed that supports mailto from html forms. Furthermore, there's no way to test for this.

So in my opinion, whether the form redirects or not (it wont redirect because there's no call to the javascript redirect function anywhere) is the least of your problems.

You should look at converting mail processing server-side with php or some other language.

Wileemarie
07-11-2007, 12:58 PM
Thanks guys!
That just confirms my suspicion that the company we are using are a bunch of kids that think they know everything. I'll be switching us to another company asap. However, in the meantime, I have NO idea how to get server-side mail processing even started - and I need this form to be working....

I understand the mailto might not work for everyone and can't be tested, but that is the guys who built this page's fault for using that - so I am covered for now, till I can correct the problem....

Can anyone provide the correct javascript to make it do what I want?


Thanks again!!

aedrin
07-11-2007, 10:19 PM
That just confirms my suspicion that the company we are using are a bunch of kids that think they know everything.

I would think that when they are using Dreamweaver for a professional site, that it would the first giveaway they're not really that professional.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum