【问题标题】:How do I add another checkbox to the php in my contact form?如何在我的联系表单中向 php 添加另一个复选框?
【发布时间】:2010-03-01 15:14:47
【问题描述】:

您好,我正在尝试在此 php 联系表单中添加一些其他字段 我有一个“您是否同意我们的业务条款”复选框,但是如何添加另一个复选框以选择加入市场营销。

感谢您的帮助

问候

朱迪

        <?php
$adminemail = 'lis@blue.co.uk'; // type your actual email address in place of you@yourdomain.com

$usesecimage = ''; // the path to a WSN Links, Gallery, KB or Forum install if you wish to borrow its security image prompt

$autoresponse = ''; // type the URL of a text file which should be used as the autoresponder body text

$controlvars = ' thankspage submitteremail ccsubmitter messagetosubmitter ';
$messagetoadmin = "A user has filled out a form with this content:


";

 if (!isset($_POST['messagetosubmitter'])) $messagetosubmitter = "You have submitted a form with the content listed below. Your submission will be reviewed, please be patient in awaiting a response.


";
 else $messagetosubmitter = $_POST['messagetosubmitter'];

while(list($key, $value) = each($_POST))
{
 if (!stristr($controlvars, ' '. $key .' '))
 {
  $messagetoadmin .= $key .': '. $value .'

';
  $messagetosubmitter .= $key .': '. $value .'

';
 }
} 
$submitter = $_POST['submitteremail'];
if ($submitter == '') $submitter = 'enquiry@blue.co.uk';
if (strstr($submitter, "\n") || strlen($submitter) > 50) die("Begone, foul spammer.");

if ($usesecimage)
{
 $curr_path = getcwd(); 
 chdir($usesecimage);        // Go to the WSN directory 
 require 'start.php'; 
 if (isset($_REQUEST['seed'])) $seed = $_REQUEST['seed']; else $seed = false;
 $correct = securityimagevalue($seed);
 if (strtolower($_POST['securityimage']) != $correct) die("You did not type the value from the image correctly. Press the back button.");
 chdir($curr_path);      // Return to original directory 
}

   session_start();
   if(empty($_POST['TermsOfBusiness']))
   {
    error_reporting(0);
    echo "You must agree to our Terms of Business. Please <a href='javascript: history.go(-1)'>click here</a> to return to the form";
   }
   elseif(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {

      mail("$adminemail, terry@blue.co.uk", 'Form Submitted: '. stripslashes($_POST['subject']), stripslashes($messagetoadmin), 'From: '. $submitter);
      unset($_SESSION['security_code']);

   } else {
      error_reporting(0);
      echo "The security code you entered was incorrect, please click the back button on your browser to try again.";
   }

if ($_POST['ccsubmitter'] == 'yes')
{
 mail($submitteremail, 'Form Submitted: '. stripslashes($_POST['subject']), stripslashes($messagetosubmitter), 'From: '. $adminemail);
}
if ($autoresponse != '')
{
 $body = geturl($autoresponse);
 mail($submitteremail, 'Re: '. stripslashes($_POST['subject']), stripslashes($body), 'From: '. $adminemail);
}
header('Location: '. $_POST['thankspage']);
// just in case redirect doesn't work
die('<meta http-eqiv="refresh" content="0;url='. $_POST['thankspage'] .'">');

if (!function_exists('geturl'))
{
function geturl($url)
{
 if (extension_loaded('curl')) 
 {
   $user_agent = 'Mozilla/4.0 (compatible; MSIE 6.02; PHP)';
   $ch = curl_init(); 
   curl_setopt ($ch, CURLOPT_URL, $url); 
   curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); 
   curl_setopt ($ch, CURLOPT_HEADER, false); 
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
   curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);  // timeout after 5 seconds
   curl_setopt ($ch, CURLOPT_TIMEOUT, 15);  // timeout after 5 seconds   
   curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); 
   $result = curl_exec ($ch); 
   curl_close ($ch); 
// curl_error($ch); // for debugging
   return $result;  
 }

 if (version_compare("4.3.0", phpversion(), "<"))
 { 
  $filecontents = @file_get_contents($url);
 }
 else
 {
  $fd = @fopen($url, 'rb');
  $filecontents = "";
  do 
  {
   $data = @fread($fd, 8192);
   if (strlen($data) == 0) 
   {
    break;
   }
   $filecontents .= $data;
  } while(true); 
  @fclose ($fd);
 }
 return $filecontents;
}
}

?>

【问题讨论】:

  • 这个si 文件看起来处理表单比生成表单更多
  • 在公共论坛发帖时,您应该屏蔽电子邮件地址!
  • 那里没有真实地址:)

标签: php forms checkbox contact


【解决方案1】:

  if(empty($_POST['TermsOfBusiness']))
   {
    error_reporting(0);
    echo "You must agree to our Terms of Business. Please click here to return to the form";
   }

此块根据需要检查业务条款。您可以在更改输入名称时简单地复制它:

  if(empty($_POST['Marketing']))
   {
    error_reporting(0);
    echo "(Place here your text for Marketing checkbox validation). Please click here to return to the form";
   }

【讨论】:

  • 非常感谢 抱歉,我改变主意了,这可以是可选字段吗?
  • 我收到此警告,但我已勾选该框?警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 已在 /home/sites 中发送标头(输出开始于 /home/sites/site.co.uk/public_html/mailer.php:1) /site.co.uk/public_html/mailer.php 第 47 行 您必须同意我们的业务条款。请单击此处返回表单选择接收营销数据。请点击这里返回表格
  • ` first 指令。是的,发生该错误是因为您在 session_start() 之前打印了数据(我可能猜到了空格)。将该命令放在第一行并从脚本中删除这些空格。那应该可以正常工作。
  • 如果你想把它作为一个可选字段,不管它的值如何,都不要抛出错误。
【解决方案2】:

这不是输入表单,这个脚本处理来自表单的输入。

【讨论】:

  • 谢谢,我知道这不是输入 html 很容易我想知道如何编辑 php,以便它将此字段识别为必填项。
猜你喜欢
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
  • 2014-11-09
  • 1970-01-01
  • 2016-08-17
相关资源
最近更新 更多