Jump to content

PHP form help, mandatory fields


shush1

Recommended Posts

Hi I have a simple form that when submitted I get sent a email with the results, however I want the 'Name' and 'Email' fields to be mandatory for the user to fill in, without which they cannot submit the form, if they try a message comes up saying they need to complete the mandatory fields.

Can someone please help or show me how I can achieve this. Thanx

this is my PHP script

<?php

$result = "Garner International: Website Enquiry Form\r\n\r\n";
$result .= "Name: " . $_POST['q1'] . "\r\n";
$result .= "Professional Title: " . $_POST['q2'] . "\r\n";
$result .= "Company Name: " . $_POST['q3'] . "\r\n";
$result .= "Email Address" . $_POST['q4'] . "\r\n";
$result .= "Comments: " . $_POST['q5'] . "\r\n";



if ($_POST['q4']) {
        $headers = "From: $_POST[q1] <$_POST[q4]>\r\n\r\n";
} else {
        $headers = "From: No Name given <[email protected]>\r\n\r\n";
}

$sendit = mail("[email protected]", "Garner International: Website Enquiry Form", $result, $headers) or die("Something went wrong");

echo "<meta http-equiv='refresh' content='0; url=thank.html'>";
die;

?>
Link to comment
https://forums.phpfreaks.com/topic/31106-php-form-help-mandatory-fields/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.