简体   繁体   English

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

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

I have a contact form that will only submit if all the fields are completed. 我有一个联系表格,只有在所有字段都填写完后才能提交。 I don't want this as many fields are optional. 我不希望这样做,因为许多字段是可选的。 I believe it has to do with this part of my code, but I am unsure how to change it and removing it will post the form automatically when the page opens. 我相信它与我的代码的这一部分有关,但是我不确定如何更改它,将其删除会在页面打开时自动发布表单。

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']))

For context here is the rest of the code. 对于上下文,这里是其余的代码。

<?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'); }
?>

Your thoughts would be greatly appreciated. 您的想法将不胜感激。

This line: 这行:

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']))

requires everything there to be filled in. 要求将其中的所有内容都填满。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM