您好我正在处理我的表单和验证过程,到目前为止一切顺利 我有一个PHP脚本,验证我的字段,因为我想要但我是PHP的新手,不知道我应该在哪里编码这部分
if( isset($_POST['name']) )
{
$to = 'myemail@gmail.com';
$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" .
在这个
里面<?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'; }
}
?>
这只是我表格的一部分。
每次尝试它都会向我发送数据而不在php中验证它。
以及如何在else {echo 'SUCCESFULL MESSAGE'; }
之后将用户带回来
提前致谢
答案 0 :(得分:1)
使用form_val
获取值
<?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 = 'myemail@gmail.com';
$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';
}
}
}
?>