xyn Posted June 29, 2006 Share Posted June 29, 2006 Hii,I used the [b]ARRAY [/b]as adviced then I wanted to have a form where the e-mail is [b]NOT [/b]required, then I tried avoiding the e-mail input and the array puts the error up anyway. So I tried to put:[code]$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."; } }[/code]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...[code]$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; }[/code] Link to comment https://forums.phpfreaks.com/topic/13226-error-update/ Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 $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--][b]$mail[/b][!--colorc--][/span][!--/colorc--]))The red text is what needs to be changed to $_POST['email'] Link to comment https://forums.phpfreaks.com/topic/13226-error-update/#findComment-50908 Share on other sites More sharing options...
xyn Posted June 29, 2006 Author Share Posted June 29, 2006 So it would look like...[code]if( !preg_match('|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z0-9]{2,4}$|i', $_POST['email']))[/code] Link to comment https://forums.phpfreaks.com/topic/13226-error-update/#findComment-50909 Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 Yes that is correct. Link to comment https://forums.phpfreaks.com/topic/13226-error-update/#findComment-50910 Share on other sites More sharing options...
xyn Posted June 29, 2006 Author Share Posted June 29, 2006 Thanks.. I have another question but it's probably better posting it Lol. Link to comment https://forums.phpfreaks.com/topic/13226-error-update/#findComment-50913 Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 Whats your question? I doen't matter if its a dumb butt question. Its what we are here for. Link to comment https://forums.phpfreaks.com/topic/13226-error-update/#findComment-50922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.