PDA

View Full Version : Problem with "required fields" in PHP



metatron
August 22nd, 2005, 02:38 PM
I have a HTML page with a e-mail form (which is connected to a PHP file). I want to put some message for "required fields" in the forms but it's not working. This is the .php file and no matter what it always shows "You need to fill some fields" even if those 3 fields are filled:




<?php
if ((!$n_empresa_field) || (!$ciudad_field) || (!$email_field))
{
Print "You need to fill some fields";
} else {

$to = "metatron@mymail.com";
$subject = "Cotización...";
$headers = 'From: metatron@mymail.com';
$n_empresa_field = $_POST['n_empresa'];
$direccion_field = $_POST['direccion'];
$colonia_field = $_POST['colonia'];
$cp_field = $_POST['cpostal'];
$dropdown = $_POST['pais'];
$dropdown2 = $_POST['estado'];
$ciudad_field = $_POST['ciudad'];
$telefono_field = $_POST['telefono'];
$n_solicitante = $_POST['n_individuo'];
$email_field = $_POST['email'];
$message = $_POST['message'];
foreach($_POST['check'] as $valor) {
$check_msg.= "$valor\n";
}
$body = "Nombre Empresa: $n_empresa_field\n Dirección: $direccion_field\n Colonia: $colonia_field\n Código Postal: $cp_field\n País: $dropdown\n Estado: $dropdown2\n Ciudad: $ciudad_field\n Teléfono: $telefono_field\n Nombre del que solicita la información: $n_individuo\n Email: $email_field\n Servicios que necesita:\n $check_msg\n Comentarios:\n $message";

echo 'Thankyou. You can close the window.';
mail($to, $subject, $body, $headers);
}
?>

metatron
August 22nd, 2005, 02:54 PM
Don't worry... I searched the forum and found the answer :)