FN-FORUM: PHP form validation Q
date posted 5th January 2005 18:22
hi all,
i'm a total PHP newb - so wondered if someone can point in the right =20
direction like ;-)
i've cribbed this mail form from somewhere and added my own stuff - =20
thing is, it only checks for an input on each field, not what that =20
input was exactly...
ideally, it needs to kick back if letters are put in the telephone =20
field. not too concerned about other fields..
any ideas??
L.
--script follows--
function dca_mailto_form($atts)
{=09
global $sitename;
if (is_array($atts)) extract($atts);
=09
if (empty($email)) {
return 'plugin txp:dca_mailto_form needs an =
email address';
}
extract(gpsa(array(
=20
'send','sender_subject','sender_email','sender_telephone','sender_day','=20=
sender_time','sender_name','other'
)));
=09
$form[] =3D "";
$form[] =3D "";
$form[] =3D "";
$form[] =3D "Your =20
full name:";
$form[] =3D "".fInput('text','sender_name',$sender_name,'','','=
=20
','30','','senderName');
$form[] =3D (!$sender_name&&$send) ? br."Please =20
enter your name" : "";
$form[] =3D "";
=09
$form[] =3D "Telephone:";
$form[] =3D "".fInput('text','sender_telephone',$sender_telepho=
=20
ne,'','','','30','','senderTelephone');
$form[] =3D (!$sender_telephone&&$send) ? br."Please enter a contact number" : "";
$form[] =3D "";
$form[] =3D "E-mail:";
$form[] =3D "".fInput('text','sender_email',$sender_email,'',''=
=20
,'','30','','senderEmail');
$form[] =3D (!$sender_email&&$send) ? br."Please =20
enter your email address" : "";
$form[] =3D "";
=09
$form[] =3D "";
$form[] =3D "I am interested in a tailor made =
trip.The best =20
time to contact me is:";
$form[] =3D "Day:";
$form[] =3D "".fInput('text','sender_day',$sender_day,'','','',=
=20
'30','','contactDay');
$form[] =3D (!$sender_day&&$send) ? br."Please =20
enter best day to contact" : "";
$form[] =3D "";
$form[] =3D "Time:";
$form[] =3D "".fInput('text','sender_time',$sender_time,'','','=
=20
','30','','contactTime');
$form[] =3D (!$sender_time&&$send) ? br."Please =20
enter best time to contact" : "";
$form[] =3D "";
$form[] =3D "";
$form[] =3D "Other:";
$form[] =3D "".text_area('other',100,300,$other,'senderMsg');
$form[] =3D (!$other&&$send) ? br."Please enter a =20
message" : "";
$form[] =3D "";
=09
$form[] =3D "";
$form[] =3D "".fInput('reset','reset','Clear and =
start =20
over')."=A0".fInput('submit','send','Send')."";
$form[] =3D "";
$form[] =3D "";
$form[] =3D "";
if (!$send) {
=09
if($_GET["sent"]) {
return "Your=
message has been sent. You =20
will be answered shortly.";
} else {
return join(n,$form);
}
=09
} else {
=09
$name_err =3D (!$sender_name) ? graf('Please =
enter your name.') : '';
$email_err =3D (!$sender_email) ? graf('Please =
enter your address.') : =20
'';
$email_err =3D (!$sender_telephone) ? graf('Please enter a contact =20
number.') : '';
$go =3D (!$name_err and !$email_err) ? true : =
false;
$message =3D
"Dear Far Frontiers,\n\nHere are my details:\n\n" .
"Name: " . $sender_name . "\n" .
"Telephone: " . $sender_telephone . "\n\n" .
"Best day to contact me: " . $sender_day . "\n\n" .
"Best time to contact me: " . $sender_day . "\n\n" .
"Anything else: " . $other . "\n\n\n" .
"Many thanks,\n\n" .
$sender_name;
if ($go) {
mail($email,"Enquiry from Far Frontiers =
site",$message,"From: =20
$sender_name \r\nX-Mailer: =20
Textpattern\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: =20
text/plain; charset=3D\"UTF-8\"\r\n");
header("Location: /contact-us/?sent=3D1");=
header("URI: /contact-us/?sent=3D1");
} else {
return join(n,$form);
}
}
}=