0

请参阅原始问题下方的更新:

我的联系表格有问题。我对 PHP 还很陌生,但是直到最近,当一个不相关的问题需要我的主机时,他们一直在努力……CBeyond :(……从 ISAPI 切换回 CGI。知道这不是那么灵活(最新) 的一项技术,我对这项技术比较熟悉,所以我可以接受。

问题开始于我的联系表格切换后都显示“未定义索引”错误。

我的所有代码都在同一个页面上(表单、处理、验证、谢谢),我正在努力找出问题所在。我确信有一些关于额外验证等的建议,但现在......我只需要这个表格就可以了。

其中一种形式:www.faa-air.com/contact/php/mailer.php 提交正确,但页面底部出现乱码。

另一种形式:www.faa-air.com/contact/php/consultmailer.php 未正确提交。它发送表单的结果,但它是空白的,网页底部仍然有所有乱码。

下面是一个不起作用的代码(consultmailer.php),但两者都是相互开发的,所以它们在逻辑上应该是相同的......所以不确定出了什么问题。

有任何想法吗?

<?php
if (empty($_POST['Submit'])) :
include 'phpconsultform.php'
?>

<?php
endif;

//FORM VALIDATION AND PROCESSING
$arrErrors = array();
if (!empty($_POST['Submit'])) 
{
  if ($_POST['f_name'] == '')
     $arrErrors['f_name'] = 'Your First Name is a Required.';
  if ($_POST['l_name'] == '')
     $arrErrors['l_name'] = 'Your Last Name is a Required.';
  if ($_POST['contactemail'] == '')
     $arrErrors['contactemail'] = 'A Valid Email Address is Required.';
  if ($_POST['contactphone'] == '')
     $arrErrors['contactphone'] = 'A Valid Phone Address is Required.';
//else if (filter_var('emailaddress', FILTER_VALIDATE_EMAIL) === FALSE)
//    $arrErrors['emailaddress'] = 'Check the format of your email.'; 
  if (count($arrErrors) == 0) 
{   

//FORM PROCESSING AFTER VALIDATION                                                                  
$f_name = $_GET['f_name'];
$l_name = $_GET['l_name'];
$email = $_GET['contactemail'];
$phone = $_GET['contactphone'];
$phone2 = $_GET['contactotherphone'];
$avail = $_GET['availability'];
$time = $_GET['timeday'];
$freq = $_GET['frequency'];
$cert = $_GET['current_cert'];
$rate = $_GET['current_rate'];
$need1 = $_GET['cert_need'];
$need2 = $_GET['rate_need'];
$TT = $_GET['TT'];
$XT = $_GET['XT'];
$COMPLX = $_GET['COMPLX'];
$IFRT = $_GET['IFRT'];
$PICT = $_GET['PICT'];
$NGT = $_GET['NGT'];
$refer = $_GET['contactrefer'] ;
$comments = $_GET['contactcomments'] ;

 $message .= 'The following request was submitted by ' .$f_name. ' ' .$l_name. "\n\n";
 //$message .= 'Please respond within 1 business day' "\n\n";
 $message .= 'Name:         ' .$f_name. ' ' .$l_name. "\n";
 $message .= 'Email:        ' .$email. "\n";
 $message .= 'Phone Number: ' .$phone. "\n";
 $message .= 'Other Phone:  ' .$phone2. "\n\n";
 $message .= 'Availability: '  ;
 {
   foreach($avail as $value)
    {
      $message .=   trim(stripslashes($value)) . "\n";
    }
 }
 $message .= 'Time of Day:  '  ;
 {
  foreach($time as $value_2)
   {
      $message .=   trim(stripslashes($value_2)) . "\n";
   }
 }
 $message .= 'Frequency:    '  ;
 {
  foreach($freq as $value_3)
   {

      $message .=   trim(stripslashes($value_3)) . "\n";
   }
 }
 $message .= "\n\n";
 $message .= 'Certifications Held:  '  ;
 $message .= "\n\n";
 {
  foreach($cert as $value_4)
   {
      $message .= "-- " . trim(stripslashes($value_4)) . "\n";
   }
 }
 $message .= "\n\n";
 $message .= 'Rating Held:  '  ;
 $message .= "\n\n";
 {
  foreach($rate as $value_5)
   {
      $message .= "-- " . trim(stripslashes($value_5)) . "\n";
   }
 }
 $message .= "\n\n";
 $message .= 'Certificates Needed:  ';
 $message .= "\n\n";
 {
  foreach($need1 as $value_6)
   {
      $message .= "-- " . trim(stripslashes($value_6)) . "\n";
   }
 }
 $message .= "\n\n";
 $message .= 'Ratings Needed:   ';
 $message .= "\n\n";
  {
   foreach($need2 as $value_7)
   {
      $message .= "-- " . trim(stripslashes($value_7)) . "\n";
   }
  }
 $message .= "\n\n";

 $message .= 'Current Logbook Times' . "\n"  ;
 $message .= 'Total Time:    ' .$TT.  "\n";
 $message .= 'Cross Country Time:    ' .$XT.  "\n";
 $message .= 'Complex Time:    ' .$COMPLX.  "\n";
 $message .= 'IFR Time:    ' .$IFRT.  "\n";
 $message .= 'PIC Time:    ' .$PICT.  "\n";
 $message .= 'Night Time:    ' .$NGT.  "\n\n";
 $message .= "\n\n" ;
 $message .= 'Refer: ' .$refer. "\n\n";
 $message .= 'Comments: ' .$comments ;
 $message .= "\n\n" ;
 $message .= "\n\n" ;
 $message .= "\n\n" ;

 mail ( "you@knowwho.com", " Custom Consult Inquiry", $message, $email) ;

 //DISPLAY THANK YOU PAGE           
 include 'thankyou.php';

}       
else
{ 
      $displayError = '<div align="center"><ul>';
    foreach ($arrErrors as $error) 
      {
               $displayError .="<li><b>$error</b></li>";
      }
           $displayError .= '</div></ul>';  

//DISPLAY FORM WITH ERRORS

include 'phpconsultform.php'

?>

<?php
        }
}
?>

更新

我能够让表格正确发送但改变了,

$f_name = $_GET['f_name'] ;

到 $f_name = $_REQUEST['f_name'] ;

我确信存在一些问题(我还是新手),但它确实有效。

我仍然收到我无法理解的 E_NOTICE 错误。我喜欢 E_NOTICE,所以如果我错过了冒号或其他东西,我可以很容易地找到它,但是我做的没有任何帮助。我很感激这个建议,并希望我能在我的错误通知中得到更多的回应。

4

1 回答 1

0

改变的只是你的错误报告级别。它现在包括E_NOTICE.

您需要在使用它们之前检查数组索引和变量。例如,而不是...

if ($_POST['f_name'] == '')

利用

if (empty($_POST['f_name']))

这是因为empty在可能未定义的变量/索引上使用是安全的。

还有一个,这个...

$f_name = $_GET['f_name'];

是安全的

$f_name = isset($_GET['f_name']) ? $_GET['f_name'] : null; // or whatever you want to use as a default value.

$message最后,在将字符串与连接运算符 ( ) 一起使用之前,您应该为字符串分配一个初始值.=,例如

// as this is the first appearance of $message, just assign the initial value directly
$message = 'The following request was submitted by ' .$f_name. ' ' .$l_name. "\n\n";
于 2013-10-29T22:40:11.230 回答