Jump to content


Photo

Error Update


  • Please log in to reply
5 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 29 June 2006 - 04:51 PM

Hii,

I used the ARRAY as adviced then I wanted to have a form where the e-mail is NOT required, then I tried avoiding the e-mail input and the array puts the error up anyway. So I tried to put:

$mail = $_POST[email];
    
    if (isset($_POST['name']) && empty($_POST['name']))
    {
    $error[] = "Your name was not provided. Please enter your name";
    }
    if (isset($_POST['artist']) && empty($_POST['artist']))
    {
    $error[] = "The Artists name was not provided. Please enter the artists name.";
    }
    if (isset($_POST['song']) && empty($_POST['song']))
    {
    $error[] = "The Song name was not provided. Please enter the Song Name.";
    }
    
    if ( isset($_POST['email']))
        {
        if( !preg_match('|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z0-9]{2,4}$|i', $mail))
        {
        $error[] = "You provided an invalid e-mail. Please check you entered it correctly.";
        }
    }

Then I still get the same errors.. So i'm not quite sure how to avoid this. But I'm trying to keep this error within the array so when it is filled incorrectly it's added with the list of errors.

my code is...

$mail = $_POST[email];
    
    if (isset($_POST['name']) && empty($_POST['name']))
    {
    $error[] = "Your name was not provided. Please enter your name";
    }
    if (isset($_POST['artist']) && empty($_POST['artist']))
    {
    $error[] = "The Artists name was not provided. Please enter the artists name.";
    }
    if (isset($_POST['song']) && empty($_POST['song']))
    {
    $error[] = "The Song name was not provided. Please enter the Song Name.";
    }
    
    if ( isset($_POST['email']))
        {
        if( !preg_match('|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z0-9]{2,4}$|i', $mail))
        {
        $error[] = "You provided an invalid e-mail. Please check you entered it correctly.";
        }
    }
    
    if (is_array($error))
        {
        
        echo "Please correct the following errors:\n<UL>\n";
        
        foreach($error as $key => $value)
            {
            
            echo "<LI>" . $value . "</UL>\n";
            
            }
            
            echo "</UL>";
        exit;
    }


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 June 2006 - 04:59 PM

$mail needs to be $_POST['email']

On this line:
if( !preg_match('|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z0-9]{2,4}$|i', [!--coloro:red--][span style=\"color:red\"][!--/coloro--]$mail[!--colorc--][/span][!--/colorc--]))

The red text is what needs to be changed to $_POST['email']

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 29 June 2006 - 05:05 PM

So it would look like...

if( !preg_match('|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z0-9]{2,4}$|i', $_POST['email']))


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 June 2006 - 05:06 PM

Yes that is correct.

#5 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 29 June 2006 - 05:13 PM

Thanks.. I have another question but it's probably better posting it Lol.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 June 2006 - 05:32 PM

Whats your question? I doen't matter if its a dumb butt question. Its what we are here for.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users