php Form sending email with unfilled fields

I know html/css but not php - I’ve honestly tried for a week to rectify this but I don’t really know what I’m looking for - someone helped me with a simple form few weeks back, but this has extra fields - help please!?

Here’s html:

[code]

Contact us today

Name or Company Name*

Email Address*

Confirm Email Address

Telephone Number*

Please give us some further information
Which of the following is of interest?

Web Design
Logo Design
Copy Writing

Other (please add comments)

Please add any further comments/information below:

Where did you hear about us? Choose Option Google Other Search Engine Facebook Facebook Advertisement Online Advertisement Card/Flyer or Print Advertisement Word of Mouth Other (please state in comments)
[/code]

Here’s php:

<?php if(isset($_POST['submit'])) { $name = $_POST['namecompany']; // required $telephone_number = $_POST['telephonenumber']; // required if(!isset($_POST['namecompany']) || !isset($_POST['telephonenumber'])){ /*Enter your * validation code * HERE! * */ } else{ $email_to = "[email protected]"; $email_subject = "Contact from Fizz Web Design"; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($namecompany)."\n"; $email_message .= "Email Address: ".clean_string($emailaddress)."\n"; $email_message .= "Email Address Confirmed: ".clean_string($emailaddressconfirm)."\n"; $email_message .= "Telephone Number: ".clean_string($telephonenumber)."\n"; $email_message .= "Web Design: ".clean_string($webdesign)."\n"; $email_message .= "Logo Design: ".clean_string($logodesign)."\n"; $email_message .= "Copy Writing: ".clean_string($copywriting)."\n"; $email_message .= "Other: ".clean_string($other)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "Google: ".clean_string($google)."\n"; $email_message .= "Other Search Engine: ".clean_string($othersearchengine)."\n"; $email_message .= "Facebook: ".clean_string($facebook)."\n"; $email_message .= "Facebook Ad: ".clean_string($facebookad)."\n"; $email_message .= "Online Ad: ".clean_string($onlinead)."\n"; $email_message .= "Card Flyer Ad: ".clean_string($cardflyerad)."\n"; $email_message .= "Word Of Mouth: ".clean_string($wordofmouth)."\n"; $email_message .= "Other: ".clean_string($other)."\n"; // create email headers $headers = 'From: Fizz Web Design'. //'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } } ?>

Anybody?
It’s just a small piece of code!? :slight_smile:

You need to validate all the required fields. Here is the lines of your code that you need to modify:
[php] $name = $_POST[‘namecompany’]; // required
$telephone_number = $_POST[‘telephonenumber’]; // required

if(!isset($_POST['namecompany']) ||
    !isset($_POST['telephonenumber'])){
  
  /*Enter your
 * validation code
 * HERE!
 * */

}
[/php]

What you need to do is - add every required field to this list. For example, if you you want to make field namecompany a mandatory, your updated code will look like this:
[php] $name = $_POST[‘namecompany’]; // required
$telephone_number = $_POST[‘telephonenumber’]; // required
$namecompany = $_POST[‘namecompany’]; // required

if(!isset($_POST['namecompany']) || $_POST['namecompany']==''  ||
    !isset($_POST['telephonenumber']) || $_POST['telephonenumber']=='' ||
    !isset($_POST['namecompany']) || $_POST['namecompany']==''){
  
    die('Please fill all the required fields!');

}
[/php]

Thanx for reply but now I get an error?

Parse error: syntax error, unexpected ‘}’ in /home/fizzweb1/public_html/send_form_contact.php on line 121

Hi,

check your code somewhere you forgot to close any if condition or foreach closing bracket.

Yes, I missed off
[php]
if(isset($_POST[‘submit’])) {
[/php]

at the start of the code - now I’m getting the messages again, but still blank…?

html/css is so much easier - this is like arguing in Russian to me!

I think, Sarthakpatel, it was you that kindly helped with the basic name/phone number form - that now works fine.

If I could get this one working it covers everything I reckon I should need going forward to adapt - radio buttons, comment area etc.

Sponsor our Newsletter | Privacy Policy | Terms of Service