Menu
I want to set up a newsletter set up form, where the user can submit their name, email, membership number, and postal code, and if their information matches mine (dealing with databases later) then they will goto a page that says “thank you” I have that fine, and a copy also ends up in my inbox. My problem is; if a user leaves the membership number, name, or email field blank, I want them to be directed to a page saying “error” nothing about what error, just that there was an error and they should try again.
Can anyone give me a hand?
Thanks.
[code=php]
// substitute the names of the required fields here:
$required = array('member_number', 'name', 'email');
foreach($required as $value)
{
if(!isset($_POST[$value]) or trim($_POST[$value] == "" )
{
header("Location: http://www.yoursite.com/error.html");
exit;
}
}
// continue with normal form processing...
[/code]
[code=html]
<?php
$required = array('realname', 'membernumber', 'email');
foreach($required as $value)
{
if(!isset($_POST[$value]) or trim($_POST[$value] == "" )
{
header("Location: http://www.yoursite.com/error.html");
exit;
}
}
?>
<html>
<head>
<title>.:Oshawa Power and Sail Squadron:.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="opss_CSS.css">
</head>
<body class="background">
<table id="Table_01" width="820" height="600" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td colspan="3" background="images/banner.gif" width="820" height="155" class="noEXT"></td>
</tr>
<tr>
<td background="images/NAV.gif" width="212" height="403" class="noEXT" id="NAV" valign="baseline">
<div align="center">
<a class="linkTEXT" href="home.htm">Home</a><br>
<a class="linkTEXT" href="events.htm">Events & Course Dates</a><br>
<a class="linkTEXT" href="newsletters.htm">Newsletters</a><br>
<a class="linkTEXT" href="officers.htm">Officers</a><br>
<a class="linkTEXT" href="history.htm">History</a><br>
<a class="linkTEXT" href="memberlogin.htm">Member's Page</a><br>
<a class="linkTEXT" href="benefits.htm">Benefits</a><br>
<a class="linkTEXT" href="classifieds.htm">Classifieds</a><br>
<a class="linkTEXT" href="links.htm">Links</a><br><br>
<a class="linkTEXT" href="contact.htm">Contacts</a><br><br>
<p class="normTEXT">Comments? Questions?</p>
<form method="post" action="http://www.oshawapss.ca/formmail.php" name="SampleForm">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />
<input type="hidden" name="subject" value="Message From Oshawa PSS" />
<input name="bad_url" type="HIDDEN" value="error.htm" />
<input name="good_url" type="HIDDEN" value="thankyou.htm" />
<input name="requirements" type="HIDDEN" value="realname:Your Name,email:Your Email Address" />
<input name="alert_to" type="HIDDEN" value="[email protected]" />
<input name="recipients" type="HIDDEN" value="[email protected],[email protected]" />
<input name="realname" type="text" value="name" size="20" maxlength="40" class="textFIELD" /><br><br>
<input name="email" type="text" value="email" size="20" maxlength="40" class="textFIELD" /><br><br>
<textarea name="comments" class="textFIELD" maxlength="1000">Comments</textarea><br><br>
<input type="submit" value="send" class="button" />
</form>
</div>
</td>
<td rowspan="2" bgcolor="#DFCCAE" width="586" height="410" class="vertEXT" valign="top">
<p class="normTEXT">If you would like to receive up-to-date news about our squadron, then please sign up for our newsletter. However, you need to be a member in order to sign up, a membership number with corresponding name and postal code will be requested.<br>
<font color="#FF0000">*</font> = Required</p>
<form method="post" action="http://www.oshawapss.ca/formmail.php" name="SampleForm">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />
<input type="hidden" name="subject" value="Request to sign up for Newsletter" />
<input name="bad_url" type="HIDDEN" value="error.htm" />
<input name="good_url" type="HIDDEN" value="thankyou.htm" />
<input name="requirements" type="HIDDEN" value="realname:Your Name,email:Your Email Address,membernumber:Your Membership Number,postal:Your Postal Code" />
<input name="alert_to" type="HIDDEN" value="[email protected]" />
<input name="recipients" type="HIDDEN" value="[email protected],[email protected]" />
<input name="realname" type="text" value="Name" size="20" maxlength="40" class="textFIELD" /><font color="#FF0000">*</font><br><br>
<input name="email" type="text" value="Email" size="20" maxlength="40" class="textFIELD" /><font color="#FF0000">*</font><br><br>
<input name="postal" type="text" value="Postal" size="20" maxlength="7" class="textFIELD" /><p class="normTEXT">(X1X 1X1)</p>
<input name="memnumber" type="text" value="Member #" size="20" maxlength="9" class="textFIELD" /><font color="#FF0000">*</font><p class="normTEXT">(123456ABC)</p>
<input type="submit" value="Send" class="button" />
</form>
<p class="titleTEXT">"Snail Mail" option</p>
<p class="normTEXT">If you dont have an e-mail address and would like to receive our newsletter by mail, please contact our <a href="mailto:[email protected]" class="linkTEXT">Newsletter Editor</a>.</p>
</td>
<td rowspan="2" background="images/rightsider.gif" width="22" height="410" class="vertEXT"></td>
</tr>
<tr>
<td background="images/vertext.gif" width="212" class="vertEXT"></td>
</tr>
<tr>
<td colspan="3" background="images/footer.gif" width="820" height="35"></td>
</tr>
</table>
</body>
</html>[/code]
why dont you use Javascript to alert the user when he leaves the fields blank. Redirecting the user to an error page for such a simple fault frustates the user.[/QUOTE]
<i>
</i>if(!isset($_POST[$value]) or trim($_POST[$value][color=red])[/color] == "" )
Where in Formmail does this go, at the beginning before anything else? I really dont like messing around with formmail, so you'll have to help me with this one.[/QUOTE]
0.1.9 — BETA 5.20