簡體   English   中英

php表格-為什么需要所有字段?

[英]Php Form - Why are all fields required?

我有一個聯系表格,只有在所有字段都填寫完后才能提交。 我不希望這樣做,因為許多字段是可選的。 我相信它與我的代碼的這一部分有關,但是我不確定如何更改它,將其刪除會在頁面打開時自動發布表單。

if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))

對於上下文,這里是其余的代碼。

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

include_once "/usr/share/pear/Swift/swift_required.php";

// Check if the form has been posted
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments'])) {

// The email address the email will be sent to
$to = 'emailaccount@website.com';
// Set the from address for the email
$from = 'emailaccount@website.com';

$headers = "Reply-To: ".$_POST["email"]."\r\n";

// The email subject
$subject = 'Contact Form Submission';

// Build the body of the email
$mailbody = "The contact form has been filled out.\n\n"
          . "first_name: " . $_POST['first_name'] . "\n"
          . "last_name: " . $_POST['last_name'] . "\n"
          . "address: " . $_POST['address'] . "\n"
          . "address_line_2: " . $_POST['address_line_2'] . "\n"
          . "city_state_zip: " . $_POST['city_state_zip'] . "\n"
          . "phone_number: " . $_POST['phone_number'] . "\n"
          . "email_address: " . $_POST['email_address'] . "\n"
          . "bedrooms: " . $_POST['bedrooms'] . "\n"
          . "baths: " . $_POST['baths'] . "\n"
          . "square_feet: " . $_POST['square_feet'] . "\n"
          . "basement: " . $_POST['basement'] . "\n"
          . "garage: " . $_POST['garage'] . "\n"
          . "house_style: " . $_POST['house_style'] . "\n"
          . "price_range: " . $_POST['price_range'] . "\n"
          . "construction: " . $_POST['construction'] . "\n"
          . "heat: " . $_POST['heat'] . "\n"
          . "features: " . $_POST['features'] . "\n"
          . "comments:\n" . $_POST['comments'];
// Create the mail transport
$transport = Swift_SmtpTransport::newInstance('smtp.domainhere.com', 587);
$transport->setUsername('emailaccount@website.com');
$transport->setPassword('123456');
$swift = Swift_Mailer::newInstance($transport);
// Create the mail
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setTo($to);
$message->setBody($mailbody);

// Send the mail
$result = $swift->send($message);
}
if ($result) 
{ 
header('Location: http://www.domainhere.com/thankyou.html'); }
?>

您的想法將不勝感激。

這行:

if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))

要求將其中的所有內容都填滿。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM