Reputation: 87
Hi i'm at processing my form and validation process , so far so good i got a php script that validate my fields as i want but i'm a novice in php and dont know where should i code this part
if( isset($_POST['name']) )
{
$to = '[email protected]';
$subject = 'NEWLOGO CLIENT FORM';
$headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];
$message = 'Name: ' . $_POST['name'] . "\n" .
'Surname: ' . $_POST['surname'] . "\n" .
'E-mail: ' . $_POST['email'] . "\n" .
'Phone: ' . $_POST['phone']. "\n" .
inside this
<?php
require_once('validator.php');
if(isset($_POST['form_btn'])) {
$validator = new simple_fv;
$fields = array();
$fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25);
$fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30);
$fields[] = array('index'=>'slider1-value', 'label'=>'Simple vs Complex');
$fields[] = array('index'=>'slider2-value', 'label'=>'Young vs Mature');
$fields[] = array('index'=>'slider3-value', 'label'=>'Luxury vs Economical');
$fields[] = array('index'=>'slider4-value', 'label'=>'Modern vs Classic');
$fields[] = array('index'=>'slider5-value', 'label'=>'Luxury vs Economical');
// validate the fields
$validator->formHandle($fields);
// get errors
$error = $validator->getErrors();
// if errors is not FALSE - print the succesfull message
if($error) {echo $error;}
else {echo 'SUCCESFULL MESSAGE'; }
}
?>
This is just a part of my form .
each time tried it sends me the data without validating it in php .
and possibly how to bring the user back after the else {echo 'SUCCESFULL MESSAGE'; }
Thanks in advance
Upvotes: 1
Views: 132
Reputation: 45490
Use form_val
to get the values
<?php
require_once('validator.php');
if(isset($_POST['form_btn'])) {
$validator = new simple_fv;
$fields = array();
$fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25);
$fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30);
$fields[] = array('index'=>'slider1-value', 'label'=>'Simple vs Complex');
$fields[] = array('index'=>'slider2-value', 'label'=>'Young vs Mature');
$fields[] = array('index'=>'slider3-value', 'label'=>'Luxury vs Economical');
$fields[] = array('index'=>'slider4-value', 'label'=>'Modern vs Classic');
$fields[] = array('index'=>'slider5-value', 'label'=>'Luxury vs Economical');
// validate the fields
$validator->formHandle($fields);
// get errors
$error = $validator->getErrors();
// if errors is not FALSE - print the succesfull message
if($error) {
echo $error;
}else {
echo 'SUCCESFULL VALIDATION!';
//send mail
$fdata = $validator->form_val;
$to = '[email protected]';
$subject = 'NEWLOGO CLIENT FORM';
$headers = 'From: ' . $fdata['email'] . "\r\n" . 'Reply-To: ' . $fdata['email'];
$message = 'Name: ' . $fdata['name'] . "\n" .
'Surname: ' . $fdata['surname'] . "\n" .
'E-mail: ' . $fdata['email'] . "\n" .
'Phone: ' . $fdata['phone']. "\n" .
//.............
if(mail($to, $subject, $message, $headers){
echo 'SUCCESFULL VALIDATION';
}else{
echo 'FAILED TO SEND';
}
}
}
?>
Upvotes: 1