Zubrag.com
October 14, 2019, 12:31:24 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Making fields "required"  (Read 3547 times)
Ahren
Newbie
*
Posts: 10


« on: May 03, 2009, 08:10:33 AM »

Hi, I have this contact form below which works just fine, except, I can submit it no problem even if nothing has been entered in any of the fields.
How do I add a code, and where, so that the fields are required? Name, Email, Subject and Message?
Thanks for any help.

Regards, Ahren


Code:
<?
///////////////////////////
//Begin Configuration
///////////////////////////

// Your email
$to = "info@example.com" . ", " ;

// Email Subject
$subject = "Message from " . "Example Online.com";

// Server name, to display in the headers
$server_name = "Example Online";

///////////////////////////
//End Configuration
///////////////////////////

if (!empty($_POST['send']) || !empty($_GET['send']))
{
$action = (!empty($_POST['send'])) ? $_POST['send'] : $_GET['send'];
}
else
{
$action = '';
}


$build_message = false;
if($action != "")
{
$build_message = true;
$message = trim($_POST['message']);
$name = trim($_POST['name']);
$email = trim($_POST['email']);
        $subject = trim($_POST['subject']);
$time = time();
$date = date("F j, Y", time());
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "From: $email\r\n";
$headers .= "X-mailer: " . $server_name . " Server\r\n";
}

if($build_message)
{
/* message */
$message = "
Sender Name: $name\n
Sender E-Mail: $email\n
Sender Subject: $subject\n 
Date Sent: $date\n
Message:\n----------------------------------------\n$message \n";

if(mail($to, $subject, $message, $headers))
{
echo '<p>' . $txt['Thank_you_for_message'] . '</p>';

}
else
echo '<p>' . $txt['error_occured'] . '</p>';
}


?>

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC