Jump to content

Defining what fields have actually been left blank


sphinx

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.