Jump to content

[SOLVED] if empty?


merylvingien

Recommended Posts

Hi guys, i have a form with a nifty bit of ajax code going on that checks a email address is valid.

This works out ok, and if the email is valid it displays a hidden field with a true value or if it is invalid it displays different hidden field with a false value.

This value gets carried over to the next page.

 

The trouble is, if a user fills out some of the form including the email field and then for some reason refreshes the page, the hidden field is no longer shown, along with the valid message or invalid message and on the next page where the value is posted there is nothing.

 

I have tried

if (empty($emailcheck)) {die etc

and that stops the user going any further, but i still get a Notice: Undefined index: emailcheck

I have also tried

if (empty($emailcheck)) {$emailcheck == "false";}

But that dont work either...

 

here is the code as it is at the moment:

 

$emailcheck = $_POST['emailcheck'];


if (empty($emailcheck)) {die ('<p>There appears to be an error with the email validation, please go back and re-enter your email address</p>');}
 else
 if ($emailcheck == 'false') {die ('<p>It appears that you have entered an invalid email address, please hit the back button in your browser and check that you have entered a valid email address.</p>');}
 else
  {

 

How can i get round this notice?

Link to comment
Share on other sites

rarebit that part works, i just can't get the other bit to work now.

 

Should this work? Cause it dont..

 

if (isset($_POST['emailcheck'])) {
 $emailcheck = 'emailcheck';
 if ($emailcheck == 'false') {die ('<p>bla bla bla</p>');}
 }
 else
 if (!isset($_POST['emailcheck'])){die ('bla bla');}
     else
  {

Link to comment
Share on other sites

the reason it disappears is because the AJAX was run in order to get that hidden input.  when the user refreshes the page, the AJAX then needs to be run again to re-obtain that value.

 

just do a valid email check in the form processing script.  this way, if somebody refreshes the page, the process script will catch them.

 

you should always have a secondary line of defense with PHP.  AJAX/javascript is all fine and dandy, it looks nice and can be a great tool for form efficiency, but it can be easily manipulated (as well as turned off), so don't ever, ever count on it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.