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. 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."; } ?> 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 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 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
Archived
This topic is now archived and is closed to further replies.