doukong1897 2014-10-06 02:03
浏览 18
已采纳

将if'(!isset)标记放在已编码的processform.php中的位置[关闭]

Hello i wanted to include a script that prevent users to make multi submission so far soo good it is working in on way that it block the user from redirecting to the destination.html after submitting one time but i get all the information even when he get the error message . So the question is this i dont know where exactly to put this code or use it for my needs :

   if (!isset($_SESSION['validsubmit']) || !$_SESSION['validsubmit']) {
        echo "ERROR:  Invalid form submission, or form already submitted!";
    } else {
        $_SESSION['validsubmit'] = false;

    }

Inside my proces php form here the shoren version :

<?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 = 'myemail@gmail.com'; 
    $subject = 'NEWLOGO CLIENT FORM'; 
    $headers = 'From: ' . $_POST['email'] . "
" . 'Reply-To: ' . $_POST['email'];    

    $message = 'Name: ' . $_POST['name'] . "
" .
               'Surname: ' . $_POST['surname'] . "
" .
               'E-mail: ' . $_POST['email'] . "
" .
               'Phone: ' . $_POST['phone']. "
" .


                     mail($to, $subject, $message, $headers);   
    if( $_POST['copy'] == 'on' )
    {
        mail($_POST['email'], $subject, $message, $headers);
    } } 

}
?>

I want to make it so that on the first submit the user go to my redictet page but on the second time not just to show this echo "ERROR: Invalid form submission, or form already submitted!" and the email need to not be send in that case.

  • 写回答

1条回答 默认 最新

  • doulei6778 2014-10-06 02:05
    关注

    You should check it immediately after you check if a form submission has occurred:

    if (isset($_POST['form_btn'])) {
        if (!isset($_SESSION['validsubmit']) || !$_SESSION['validsubmit']) {
            echo "ERROR:  Invalid form submission, or form already submitted!";
        } 
        else {
            $_SESSION['validsubmit'] = false;
            $validator = new simple_fv;
            // ...
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥500 火焰左右视图、视差(基于双目相机)