sphinx Posted September 23, 2011 Share Posted September 23, 2011 Hello, I'm using the below code to determine whether fields have been left blank, however, it only a standard sentence, i'd like to customise it, like: "Email has been left blank" or The email and message has been left blank. My best preference would be to bullet point each line. IE: Email has been left blank. Message has been left blank. $name = $_POST['name']; $visitor_email = $_POST['email']; $user_message = $_POST['message']; if(empty($name)|| empty($visitor_email)|| empty($user_message)) { $errors .= "\n Some of the above fields have not been filled in.<br><br> "; } Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/247740-defining-what-fields-have-actually-been-left-blank/ Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 c'mon, I'm sure you can figure it out by looking at your code. Here's a "basic" version: <?php $name = trim($_POST['name']); $visitor_email = trim($_POST['email']); $user_message = trim($_POST['message']); if(empty($name){ $errors .= "<br />Name is empty."; } if(empty($visitor_email){ $errors .= "<br />Email is empty."; } if(empty($user_message){ $errors .= "<br />User Message is empty."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247740-defining-what-fields-have-actually-been-left-blank/#findComment-1272168 Share on other sites More sharing options...
sphinx Posted September 23, 2011 Author Share Posted September 23, 2011 Sorry this has got me, what's a trim. edit: unexpected '{ Cheers Quote Link to comment https://forums.phpfreaks.com/topic/247740-defining-what-fields-have-actually-been-left-blank/#findComment-1272169 Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 oppss, typo: <?php $name = trim($_POST['name']); $visitor_email = trim($_POST['email']); $user_message = trim($_POST['message']); if(empty($name)){ $errors .= "<br />Name is empty."; } if(empty($visitor_email)){ $errors .= "<br />Email is empty."; } if(empty($user_message)){ $errors .= "<br />User Message is empty."; } ?> trim will remove any empty spaces from the beginning and end of variables, and other characters (hidden line breaks)... check it out: trim Quote Link to comment https://forums.phpfreaks.com/topic/247740-defining-what-fields-have-actually-been-left-blank/#findComment-1272172 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.