Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add additional required fields in PHP form...?

Guest
Jun 16, 2009 Jun 16, 2009

I wrote on here a couple of days ago about how to validate a PHP form I was working on.

I found that the method I was using was not the best option so I have moved on to a new script.

The form I have now looks the way I want it to, send the information to email correctly, and validates.

Now, I am trying to figure out how to edit the PHP sendform file to require that additional fields are filled in.

The form is located at http://www.mosaleen.com/contact.html and the PHP script for the formmail file is below.

I would like the script to require the name and message to be filled out. How would I edit the formmail script to make this happen? Currently it only routes to the error.html page if the email field is left empty.

Thanks in advance!!!

Andrea

<?php


$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "svanhoose57@hotmail.com";
$Subject = "Comments from MoSaleen";
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$phone = Trim(stripslashes($_POST['phone']));
$message = Trim(stripslashes($_POST['message']));

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "message: ";
$Body .= $message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$email>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou_email.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

TOPICS
Server side applications
488
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2009 Jun 16, 2009
LATEST

Followed my instinct and added the code below... guess what? It worked!

Thanks again.


if (Trim($name)=="") $validationOK=false;
if (Trim($message)=="") $validationOK=false;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines