Page 1 of 1

validation for a beginner

Posted: Fri Jan 28, 2005 8:12 am
by Addos
I’m going mad trying to sort this out so I’m wondering if anybody can see what I’m missing here because for some reason I keep getting the message 'invalid email'. I’m sure the expression is ok as I’m using this from another form that I have but obviously I’m missing something else vital.
Thanks for any advice
Brian

Code: Select all

<?php	$pattern = '/^\w&#1111;-.\w]*@(&#1111;-a-z0-9]+\.)+&#1111;a-z]&#123;2,4&#125;$/i';
	if ($_POST && array_key_exists('send',$_POST)) &#123;
	  $nomessage='';
	  $error=array();
	  $message='';
	  $guestemail= '';
	 // Check each field and build errors array if problems found

	 if (empty($_POST&#1111;'guestemail'])) &#123;
	 echo 'empty email'; // to be removed once working
	 &#125; else &#123;
	 if (!preg_match($pattern,$guestemail)) $error&#1111;'invalid'] = 'invalid email';
     &#125;
	 echo 'validate code running'; // to be removed once working
	 &#125;
?>

      <form method="post" name="form1" action="">
        <table align="center" class="mainContent">
          <tr valign="baseline">
		 <td nowrap align="right">Email Address:
			<?php 
	  if (isset($error)) &#123;	  
		foreach ($error as $key => $value) &#123;
		  echo $value.'<br />';
		  &#125;
		  &#125;
		?>
	  </td>
            <td><input type="text" name="guestemail" id="guestemail" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td nowrap align="right">&nbsp;</td>
            <td><input name="send" type="submit" id="sendCom" value="Post Message" />	   </td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1">
      </form>

Posted: Fri Jan 28, 2005 8:15 am
by feyd
$guestemail is set to an empty string.

Posted: Fri Jan 28, 2005 8:22 am
by Addos
Thansk for this. I popped in $guestemail= $_POST['guestemail']; and it now works ok. Can I just ask your expert advice if this is what I should have done.
Thanks a mill for your fast help.
Brian

Posted: Fri Jan 28, 2005 8:29 am
by feyd
yep.