cattledogz Posted April 5, 2006 Share Posted April 5, 2006 I need help...I was able to orginally get my form to process multi-checkbox arrays and email it... But now, I need to validate the email address of the person using the form...So.. I started out with a simple form... just to get it working before tacking the huge form that it eventually needs to go on...[code]<?php$email = $_POST['txtemail'];$formaction = $_POST['action']?><?function checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(@getmxrr($Domain, $MXHost)) { return TRUE; } else { if(@fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } }}?><form name="form1" method="post" action="<?echo $_SERVER['PHP_SELF'];?>"><table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#0033FF" bgcolor="#DEE3EF" ><tr><td width="100%"><table width="60%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#DEE3EF"><caption align="top" class="heading">E-Mail Validation<br><tr><td width="46%"><br><?if(checkEmail($email) == FALSE) { echo '<div align="right"><font color=red>Invalid Email Address</font></td><td width="54%"><br>';} //else //{// ( $email != '' && $formaction == 'submit');//}if(checkEmail($email) == TRUE){( $email == '' && $formaction == 'submit');}$info = $info ."it works!";mail("bluecattledogz@yahoo.com","RFID Survey Submission",$info,"From: $email");//if ( $email == '' && $formaction == 'submit') {// echo '<div align="right"><font color=red>Invalid Email Address</font></td><td width="54%"><br>';//}else{// echo '<div align="right">Enter An Email Address </td><td width="54%"><br>';//}?><input name="txtemail" type="text" class="textbox" id="txtemail" value="<?php echo $stremail; ?>"> </tr> <tr> <td colspan="2"> <div align="center"><br><input name="Submit" type="submit" class="button" value="Submit"><input name="action" type="hidden" value="submit"> </div></td></tr></td><?if ( $email != '' && $formaction == 'submit') { // echo "Thanks"; echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><script LANGUAGE="JavaScript"><!-- BeginredirTime = "0";redirURL = "http://www.rfid-solutions.ca";function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }// End --></script></HEAD><BODY><BODY onLoad="redirTimer()"></BODY></HTML>';}[/code]I have a couple of problems...1 - It sends me email when the page loads...2. - It declares that the email is invalid on first load3. - Its not validating the email addy... Only if the field is left blank. I can just put in "haha" and it sends mail (attaches the server's domain) What did I di wrong?Jen Quote Link to comment Share on other sites More sharing options...
bbaker Posted April 5, 2006 Share Posted April 5, 2006 [i]1 - It sends me email when the page loads...[/i] This is probably because you code isn't inside the body of the page.[i]2. - It declares that the email is invalid on first load[/i] This happens because you're running the checkEmail() function in the middle of your form, before you even submit.[i]3. - Its not validating the email addy... Only if the field is left blank. I can just put in "haha" and it sends mail (attaches the server's domain)[/i] Not a big eregi() guru, so can't tell you for sure.But....you should take a look at your logic a bit.You're setting the variables for $email & $formaction when the page loads, whether the form has been submitted or not. Look like you //'d out an attempt at this. Do a check before setting them (maybe better ways):[code]if(!isset($_POST['txtemail']) {$email = $_POST['txtemail'];$formaction = $_POST['action']; //might not even need the $formaction varible if you do this correctly//then do your validation here.}else { //show your form}[/code]everthing that is echo'd to the browser should be inside the <body> tags regardless.Also, I didn't see where you closed the form or table tags Quote Link to comment Share on other sites More sharing options...
cattledogz Posted April 5, 2006 Author Share Posted April 5, 2006 Well.. I mucked around with it some... still couldn't get it to work.... so I started over with just :[code]<?php$email = $_POST['txtemail'];$formaction = $_POST['action']?><form name="form1" method="post" action="<?echo $_SERVER['PHP_SELF'];?>">E-Mail Validation<br><input name="txtemail" type="text" class="textbox" id="txtemail" value="<?php echo $stremail; ?>"><input name="Submit" type="submit" class="button" value="Submit"><input name="action" type="hidden" value="submit"></form><?if (checkEmail($email)) { echo $email . ' is a valid email address.';$info = $info ."it works!";mail("bluecattledogz@yahoo.com","RFID Survey Submission",$info,"From: $email");} else { echo $email . '<font color="red"> is not a valid email address.</font>';}?><?function checkEmail($email){ if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(@getmxrr($Domain, $MXHost)) { return TRUE; } else { if(@fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } }}?>[/code]Now... I got one of my problems fixed... (yay!)BUT... when the page loads, it still comes up says" invalid email"... and it still sends mail...I'm pretty sure that that sending mail part would be something like:[code]<?if (checkEmail($email)) { echo $email . ' is a valid email address.';$info = $info ."it works!";mail("bluecattledogz@yahoo.com","RFID Survey Submission",$info,"From: $email");} else { echo $email . '<font color="red"> is not a valid email address.</font>';}?>[/code]I put in a hidden <input name="action" type="hidden" value="mailit"> but I'm not sure how to draw that into my funtion to send email apon submitting with a valid email addy.ack!php=pretty hard programingjen Quote Link to comment Share on other sites More sharing options...
cattledogz Posted April 5, 2006 Author Share Posted April 5, 2006 Problem solved!!Thanks so much!!Jen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.