Jump to content
Larry Ullman's Book Forums

Recommended Posts

I would like to see an example of the filter_var() used to validate an email address in register.php from Chapter 8 Review and Pursue. I've tried a million things but it's not catching errors correctly so I think my IF conditional is off.

 

// original code for email validation:

if (empty($_POST['email']) || (substr_count($_POST['email'], '@') != 1) ) {

$problem = TRUE;

print '<p class="error">Please enter your email address!</p>';

}

 

Thank you!

Jill

Link to post
Share on other sites

Sure, that'd be:

if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
   $problem = TRUE;
   // Etc.

 

I'd be inclined to add an isset() clause to that conditional, too, but that's a minor point.

Link to post
Share on other sites
  • 5 months later...

I'm still a little confused understanding the differences between the empty() or isset() functions. In the above you suggest using the isset() clause on the 'email' variable, would it not work with empty()?. Think I remember reading you'd use isset on checkboxes, radio buttons alike.

 

Please explain?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...