czukoman20 Posted June 3, 2008 Share Posted June 3, 2008 How would i make a form that gives you an error message if something isn't filled in Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/ Share on other sites More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 By checking if everything is set, and if it's not, returning an error. A little bit of common sense goes a long way. We're not writing it for you, but we'll help you get on the right road to doing it. Show us what you have so far. Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-556891 Share on other sites More sharing options...
Jabop Posted June 3, 2008 Share Posted June 3, 2008 if (!isset($_REQUEST['field'])) { echo "Blank"; } Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-556892 Share on other sites More sharing options...
czukoman20 Posted June 3, 2008 Author Share Posted June 3, 2008 Well all i have is a simple textbox. in this form <input type="text" name="fname" maxlength="50" value="<? echo $form->value("fname"); ?>" Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-556905 Share on other sites More sharing options...
Jabop Posted June 3, 2008 Share Posted June 3, 2008 Less vague please, that code doesn't tell much. What I told you in my previous post works fine. Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-556910 Share on other sites More sharing options...
chronister Posted June 3, 2008 Share Posted June 3, 2008 <?php if(empty($_POST['fname'])) { $error = 'Please enter your first name'; } if(isset($error)) { echo $error; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-557040 Share on other sites More sharing options...
czukoman20 Posted June 4, 2008 Author Share Posted June 4, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-557061 Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 You should make $error an array so you can store multiple errors, or make a FormError class. Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-557062 Share on other sites More sharing options...
chronister Posted June 4, 2008 Share Posted June 4, 2008 You should make $error an array so you can store multiple errors, or make a FormError class. Typically when validating multiple fields I will either use an array or concatenate the strings. For the original poster we are talking about this..... <?php if(empty($_POST['fname'])) { $error['first_name'] = 'Please enter your first name'; } if(empty($_POST['another_field'])) { $error['some_field'] = 'Please enter data in this field '; } if(isset($error)) { foreach($error as $k=>$v) { echo $v.'<br>'; } } ?> OR <?php if(empty($_POST['fname'])) { $error .= 'Please enter your first name<br>'; } if(empty($_POST['another_field'])) { $error .= 'Please enter data in this field<br>'; } if(isset($error)) { echo $error; } ?> Nate Quote Link to comment https://forums.phpfreaks.com/topic/108593-solved-form-error-messages/#findComment-557079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.