douweibiao8471 2012-11-19 07:56
浏览 9

复选框值未显示

The form inputs aren't displaying on the form.php page and negates my form validation. The error says undefined variable for all my variables on form.php. Please tell me what I have to edit in my code to make it display the form inputs on form.php. It works when I use it on the same page but I would rather it display on another page.


EDIT

Thanks so far but I can't get the value of the checkbox, the recipient(Administrator or Content Editor), to display it displays "Array" or "A".

contact.php

   <?php
    $errnam = "";
    $errmail = "";
    $errsub = "";
    $errrec = "";
    $hasErrors = false;

    if(isset ($_POST['submitted'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $recipient = $_POST['recipient'];
    $message = $_POST['message'];



            if(preg_match("/^[\w\-'\s]/", $_POST['name'])){
               $name = $_POST['name'];   
            }  
            else{  
                 $errnam ='<strong>Please enter a name.</strong>';
                 $hasErrors = true;  
            }  

            if (preg_match("/^[\w.-_]+@[\w.-]+[A-Za-z]{2,6}$/i", $email)){
              $email = $_POST['email'];

            }  
            else{  
                $errmail = '<strong>Please enter a valid email.</strong>';
                $hasErrors = true;  
            } 


            if(preg_match("/^[\w\-'\s]/", $_POST['subject'])){
                $subject = $_POST['subject'];

            }  
            else{  
                 $errsub = "<strong>Please enter a subject.</strong>";
                 $hasErrors = true; 
            }

            if (!empty($_POST['recipient'])) {  
             for ($i=0; $i < count($_POST['recipient']);$i++) {
                 $recipient = $_POST['recipient'];
                  }
           }else{
            $errrec = "<strong>Please select a recipient</strong>";
            $hasErrors = true; 
          } 
                $message = $_POST['message'];
    }

    if ($hasErrors){
        echo "<strong>Error! Please fix the errors as stated.</strong>";
    }else{
        header("Location: form.php?name=".$name."&email=".$email."&subject=".$subject. "&recipient=".$recipient. "&message=".$message);

    exit();

}
?>

form.php

<?php
$name = $_GET['name'];
$email = $_GET['email'];
$subject = $_GET['subject'];
$recipient = $_GET['recipient'];
$message = $_GET['message'];

echo "<h2>Thank You</h2>";
echo "<p>Thank you for your submission. Here is a copy of the details that you have sent.</p>"; 
echo "<strong>Your Name:</strong> ".$name. "<br />";
echo "<strong>Your Email:</strong> ".$email. "<br />";
echo "<strong>Subject:</strong> ".$subject. "<br />";
echo "<strong>Recipient:</strong>" .$recipient. "<br />";  
echo "<strong>Message:</strong> <br /> " .$message;
?>
  • 写回答

4条回答 默认 最新

  • douyan8070 2012-11-19 08:00
    关注

    The problem is when you header("Location:") to form.php, all the POST values are lost. You have to either resend them with the header, or modify them into GET and retrieve them again. It should be more efficient to have them both (contact.php AND form.php) in one page. That way, the form data only has to be sent once.

    You could probably just send the POST values as GET over to form.php like this.

    contact.php:

    header("Location: form.php?name=".$name."&email=".$email."&subject=".$subject."&message=".$message);
    

    form.php (to retrieve the values):

    $name = $_GET['name'];
    $email = $_GET['email'];
    $message = $_GET['message'];
    $subject = $_GET['subject'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类