-1
你好,我想包括一个脚本,防止用户多次提交到目前为止好哟 正在工作,用户在提交一次后重定向到destination.html,但即使他得到了错误信息,我也能得到所有信息。所以问题是这个我不知道究竟在哪里放这个代码或用它来满足我的需求:把'(!isset“)标签放在一个已经编码好的processform.php中
if (!isset($_SESSION['validsubmit']) || !$_SESSION['validsubmit']) {
echo "ERROR: Invalid form submission, or form already submitted!";
} else {
$_SESSION['validsubmit'] = false;
}
在我的理线的PHP这里的形式shoren版本:
<?php
session_start();
require_once('formvalidator.php');
if(isset($_POST['form_btn'])) {
$validator = new simple_fv;
// fields info container
$fields = array();
// fill the container with fields data
$fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25);
$fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30);
$indexes[] = array('index'=>'email', 'label'=>'E-mail', 'required'=>true, 'type'=>'email', 'max_len'=>200);
$fields[] = array('index'=>'phone', 'label'=>'phone number', 'required'=>true, 'type'=>'int', 'min_len'=>4);
// 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 {if(isset($_POST['name']))
$emotion = $_POST['emotion'];
if($emotion == 'Basic Pack') {
session_start();
$_SESSION['form_finished'] = true;
header('Location: /destination/basicc.php');
} elseif($emotion == 'Deluxe Pack') {
header('Location: html6.php');
} elseif($emotion == 'Premium Pack') {
header('Location: html7.php');
}
$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" .
mail($to, $subject, $message, $headers);
if($_POST['copy'] == 'on')
{
mail($_POST['email'], $subject, $message, $headers);
} }
}
?>
我想使它在第一次提交用户转到我的redictet页面,但在第二次不只是显示此回声"ERROR: Invalid form submission, or form already submitted!"
和电子邮件需要不发送在这种情况下。
我只是想你的答案,我得到错误“头已经发出”而行正是第一头开始的地方在这种情况下:'header('Location:/destination/basicc.php'); '除了这个谢谢 – 2014-10-06 02:13:54
它的工作@约翰孔德我犯了一个错误,非常感谢你,这是我完成我的表格的最后一部分有一个愉快的一天:) – 2014-10-06 02:19:01