我继承了一个带有已停止工作的 PHP 表单的网站。编码水平超出了我的技能,但是我认为可能有一个简单的解决方案,就像以前的表单一样。是否需要添加一段 PHP 代码才能使提交按钮发布收集到的信息?这是完整的表单,但删除了一些 HTML 文本(替换为“文本已删除”)以避免帖子被标记为垃圾邮件:
<?php
/**
* Template Name: Package
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
*/
get_header(); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<article id="package" class="page">
<div class="entry-content">
<div class="home-wrap side-padding max-width-1000">
<h1 class="page-title-handwriting padding-top-0pt4em"><?php the_title(); ?></h1>
</div>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') : ?>
<?php // Grab submitted fields
$flagStyle = $_POST['flag-style'];
$palette = $_POST['palette'];
$noOfFlags = $_POST['no-of-flags'];
$addBunting = $_POST['add-bunting'];
$buntingLocation = $_POST['bunting-location'];
$buntingLength = $_POST['length'];
$deliveryOption = $_POST['delivery-option'];
$buntingRefolding = $_POST['bunting-refolding'];
$firstName = $_POST['your-first-name'];
$surname = $_POST['your-surname'];
$emailAddress = $_POST['your-email'];
$phoneNumber = $_POST['your-phone'];
$eventDate = $_POST['event-date'];
$eventEndDate = $_POST['event-end-date'];
$eventPostcode = $_POST['event-postcode'];
$deliveryAddress = $_POST['delivery-address'];
$deliveryAddressType = $_POST['delivery-address-type'];
$deliveryContact = $_POST['event-contact'];
$additionalComments = $_POST['additional-comments'];
// Send the details by email
$headers = "From: Event Flag Hire<[email protected]>\r\n" . 'Reply-To: ' . $emailAddress;
$to = "[email protected]";
$to = "[email protected]";
$subject = "PACKAGE QUOTE ENQUIRY FORM";
$message = "
CUSTOMER DETAILS\r\n
Name: {$firstName} {$surname}\r\nEmail: {$emailAddress}\r\nTelephone: {$phoneNumber}\r\n";
$message .= "
FLAG SPECIFICATION\r\n
Flag Style: {$flagStyle}\r\nPalette: {$palette}\r\nNumber of flags: {$noOfFlags}\r\n";
$message .= "
ADD ADDITIONAL BUNTING?\r\n
Would you like to add additional bunting?: {$addBunting}\r\n";
$message .= "Bunting location: {$buntingLocation}\r\n";
if($addBunting == 'Yes'){
$message .= "Bunting length: {$buntingLength}m\r\n";
}
$message .= "
Bunting refolding required?: {$buntingRefolding}\r\n";
$message .= "
DELIVERY\r\n
Delivery option: {$deliveryOption}\r";
if($deliveryOption == 'Deliver'){
$message .= "
Address Type: {$deliveryAddressType}";
}
$message .= "
\r\nEVENT DETAILS\r\n
Event date: {$eventDate}\r\nEnd date (if event is more than one day): {$eventEndDate}\r\n";
if($deliveryOption == 'Deliver'){
$message .= "\r\nDelivery address:
{$deliveryAddress}\r\n{$eventPostcode}\r\nDelivery contact: {$deliveryContact}\r\n";
}
$message .= "
ADDITIONAL COMMENTS\r\n
{$additionalComments}\r\n";
mail($to, $subject, $message, $headers);
?>
<div class="home-wrap side-padding max-width-1000" style="text-align:center;">
<h3 class="center padding-top-1em padding-bottom-1em no-text-transform mobile-side-padding text-left"><strong>Thanks for sending your enquiry through for your flag package.</strong></h3>
<p>We will send text removed</p>
<p>For more decor please <a href="text removed">text removed</a>.</p>
</div>
<?php else: ?>
<form id="package-enquiry-form" method="post" action="<?php the_permalink(); ?>">
<div id="package-loader" class="clearboth flag-strip">
<div class="loader">Loading, please wait&helip;</div>
</div>
<div id="package-step01" class="clearBoth flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 1:</strong> Choose your flag style</legend>
<div class="home-wrap flag-styles">
<div class="center-big-flags center-big-flags-7">
<div class="flag-blueprint teal-hover">
<div>
<input type="radio" class="flag-style" value="New Leaf" name="flag-style" id="flag-style-new-leaf">
<label for="flag-style-new-leaf" title="New Leaf">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Festival Flags New Leaf" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint turquoise-hover">
<div>
<input type="radio" class="flag-style" value="Silk & Ribbon" name="flag-style" id="flag-style-silk-and-ribbon">
<label for="flag-style-silk-and-ribbon" title="Silk & Ribbon">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Festival Flags Silk & Ribbon" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint teal-hover">
<div>
<input type="radio" class="flag-style" value="Half Moon Petal" name="flag-style" id="flag-style-half-moon-petal">
<label for="flag-style-half-moon-petal" title="Half Moon Petal">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Festival Flags Half Moon Petal" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint turquoise-hover">
<div>
<input type="radio" class="flag-style" value="Indian Summer" name="flag-style" id="flag-style-indian-summer">
<label for="flag-style-indian-summer" title="Indian Summer">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Festival Flags Indian Summer" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint teal-hover">
<div>
<input type="radio" class="flag-style" value="Phoenix" name="flag-style" id="flag-style-phoenix">
<label for="flag-style-phoenix" title="Phoenix">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Phoenix Festival Flag Blueprint" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint turquoise-hover">
<div>
<input type="radio" class="flag-style" value="Bright Stripes" name="flag-style" id="flag-style-bright-stripes">
<label for="flag-style-bright-stripes" title="Bright Stripes">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Festival Flags Bright Stripes" />
</div>
</label>
</div>
</div>
<div class="flag-blueprint teal-hover">
<div>
<input type="radio" class="flag-style" value="Calypso" name="flag-style" id="flag-style-calypso">
<label for="flag-style-calypso" title="Calypso">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-timeout=2000>
<img src="text removed" alt="Calypso Flag Blueprint" />
</div>
</label>
</div>
</div>
</div>
<div class="home-wrap topTwoButtons clearBoth" style="overflow:hidden; margin-top:32px;">
<div class="inline-button">
<input type="radio" class="flag-style" value="Choose for me" name="flag-style" id="flag-style-choose-for-me">
<label for="flag-style-choose-for-me">I love them all, choose for me</label>
</div>
</div>
</div>
</fieldset>
</div>
<div id="package-step02" class="clearBoth teal-background flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 2:</strong> Choose your colour palette</legend>
<p>Get inspired by selecting one of our beautiful pre-set palettes below.</p>
<ul class="palettes">
<li class="swatch-festival-mix">
<input type="radio" class="palette" value="Festival Mix" name="palette" id="palette-festival-mix">
<label for="palette-festival-mix" title="Festival Mix">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/festival-mix.svg" alt="Festival Mix">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Festival-Mix-Rollover.jpg" alt="Festival Mix">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Festival-Mix-Rollover-02.jpg" alt="Festival Mix">
</div>
</label>
</li>
<li class="swatch-warm-hues">
<input type="radio" class="palette" value="Warm Hues" name="palette" id="palette-warm-hues">
<label for="palette-warm-hues" title="Warm Hues">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/warm-hues.svg" alt="Warm Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Warm-Hues-Rollover.jpg" alt="Warm Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Warm-Hues-Rollover-02.jpg" alt="Warm Hues">
</div>
</label>
</li>
<li class="swatch-under-the-sea">
<input type="radio" class="palette" value="Under the Sea" name="palette" id="palette-under-the-sea">
<label for="palette-pastels" title="Under the Sea">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/under-the-sea.svg" alt="Under the Sea">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Under-the-Sea-Rollover.jpg" alt="Under the Sea">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Under-the-Sea-Rollover-02.jpg" alt="Under the Sea">
</div>
</label>
</li>
<li class="swatch-pastels">
<input type="radio" class="palette" value="Pastels" name="palette" id="palette-pastels">
<label for="palette-pastels" title="Pastels">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/pastels.svg" alt="Pastels">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Pastels-Rollover.jpg" alt="Pastels">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Pastels-Rollover-02.jpg" alt="Pastels">
</div>
</label>
</li>
<li class="swatch-white-ivory">
<input type="radio" class="palette" value="White & Ivory" name="palette" id="palette-white-ivory">
<label for="palette-white-ivory" title="White & Ivory">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/white-ivory.svg" alt="White & Ivory">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/White-Ivory-Rollover.jpg" alt="White & Ivory">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/White-Ivory-Rollover-02.jpg" alt="White & Ivory">
</div>
</label>
</li>
<li class="swatch-multicolour-rainbow">
<input type="radio" class="palette" value="Multicolour Rainbow" name="palette" id="palette-multicolour-rainbow">
<label for="palette-multicolour-rainbow" title="Multicolour Rainbow">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/multicolour-rainbow.svg" alt="Multicolour Rainbow">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Rainbow-Rollover.jpg" alt="Multicolour Rainbow">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Rainbow-Rollover-02.jpg" alt="Multicolour Rainbow">
</div>
</label>
</li>
<li class="swatch-multicolour-warm-hues">
<input type="radio" class="palette" value="Multicolour Warm Hues" name="palette" id="palette-multicolour-warm-hues">
<label for="palette-multicolour-warm-hues" title="Multicolour Warm Hues">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/multicolour-warm-hues.svg" alt="Multicolour Warm Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Warm-Hues-Rollover.jpg" alt="Multicolour Warm Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Warm-Hues-Rollover-02.jpg" alt="Multicolour Warm Hues">
</div>
</label>
</li>
<li class="swatch-multicolour-cool-hues">
<input type="radio" class="palette" value="Multicolour Cool Hues" name="palette" id="palette-multicolour-cool-hues">
<label for="palette-multicolour-cool-hues" title="Multicolour Cool Hues">
<div class="cycle-slideshow" data-cycle-fx=fadeout data-cycle-speed="500" data-cycle-timeout=1000>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/multicolour-cool-hues.svg" alt="Multicolour Cool Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Cool-Hues-Rollover.jpg" alt="Multicolour Cool Hues">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/swatches/rollovers/Multicolour-Cool-Hues-Rollover-02.jpg" alt="Multicolour Cool Hues">
</div>
</label>
</li>
</ul>
</fieldset>
</div>
<div id="package-step03" class="clearBoth flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 3:</strong> How many flags do you need?</legend>
<div class="inline-buttons">
<div class="inline-button">
<input type="radio" class="number-of-flags" value="6 flags + 25m bunting" name="no-of-flags" id="flags-6">
<label for="flags-6">6 FLAGS <span>+ 25m bunting</span></label> <span><strong>£235 (ex VAT)</strong><br>£282 (inc VAT)</span>
</div>
<div class="inline-button">
<input type="radio" class="number-of-flags" value="10 flags + 40m bunting" name="no-of-flags" id="flags-10">
<label for="flags-10">10 FLAGS <span>+ 40m bunting</span></label> <span><strong>£340 (ex VAT)</strong><br>£408 (inc VAT)</span>
</div>
<div class="inline-button">
<input type="radio" class="number-of-flags" value="20 flags + 50m bunting" name="no-of-flags" id="flags-20">
<label for="flags-20">20 FLAGS <span>+ 50m bunting</span></label> <span><strong>£565 (ex VAT)</strong><br>£678 (inc VAT)</span>
</div>
<div class="inline-button">
<input type="radio" class="number-of-flags" value="25 flags + 100m bunting" name="no-of-flags" id="flags-25">
<label for="flags-25">25 FLAGS <span>+ 100m bunting</span></label> <span><strong>£750 (ex VAT)</strong><br>£900 (inc VAT)</span>
</div>
</div>
</fieldset>
</div>
<div id="package-step04" class="clearBoth teal-background flag-strip">
<fieldset class="teal-background package-section-title side-padding max-width-1000">
<legend><strong>Step 4:</strong> Would you like to add additional bunting?</legend>
<div class="home-wrap topTwoButtons" style="overflow:hidden;">
<div class="col-half">
<div class="inline-button">
<input type="radio" class="add-bunting" value="Yes" name="add-bunting" id="add-bunting-yes">
<label for="add-bunting-yes">YES</label>
</div>
</div>
<div class="col-half">
<div class="inline-button">
<input type="radio" class="add-bunting" value="No" name="add-bunting" id="add-bunting-no">
<label for="add-bunting-no">NO</label>
</div>
</div>
</div>
<fieldset class="package-section-title side-padding max-width-1000">
<legend>Is your bunting for inside or outside use?</legend>
<div class="home-wrap topTwoButtons">
<div class="col-half">
<div class="inline-button">
<input type="radio" value="Inside" name="bunting-location" id="bunting-location-inside">
<label for="bunting-location-inside">INSIDE</label>
</div>
</div>
<div class="col-half">
<div class="inline-button">
<input type="radio" value="Outside" name="bunting-location" id="bunting-location-outside">
<label for="bunting-location-outside">OUTSIDE</label>
</div>
</div>
</div>
</fieldset>
<div id="extra-bunting-options">
<fieldset class="package-section-title side-padding max-width-1000">
<legend>Choose your length in metres</legend>
<div class="bunting-length">
<label for="length">Length</label>
<input class="text" type="number" name="length" id="length" min="10" step="10" value="20" onKeyDown="return false">
</div>
<div class="bunting-price">
<p>£<span class="price">text removed</span> + VAT <small>per metre</small></p>
</div>
</fieldset>
</div>
<fieldset class="teal-background package-section-title side-padding max-width-1000">
<legend>Would you like a text removed</legend>
<div class="home-wrap topTwoButtons">
<div class="col-half">
<div class="inline-button">
<input type="radio" class="bunting-refolding" value="Yes" name="bunting-refolding" id="bunting-refolding-yes">
<label for="bunting-refolding-yes">YES</label> <span>text removed</span>
</div>
</div>
<div class="col-half">
<div class="inline-button">
<input type="radio" class="bunting-refolding" value="No" name="bunting-refolding" id="bunting-refolding-no">
<label for="bunting-refolding-no">NO</label> <span>text removed</span>
</div>
</div>
</div>
</fieldset>
</fieldset>
</div>
<div id="package-step05" class="clearBoth flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 5:</strong> Choose your delivery option</legend>
<div class="home-wrap topTwoButtons">
<div class="col-half">
<div class="inline-button">
<input type="radio" class="delivery-option" value="Deliver" name="delivery-option" id="delivery-option-deliver">
<label for="delivery-option-deliver">DELIVER</label> <span>text removed</span>
</div>
</div>
<div class="col-half">
<div class="inline-button">
<input type="radio" class="delivery-option" value="Collection" name="delivery-option" id="delivery-option-collection">
<label for="delivery-option-collection">COLLECT</label> <span>text removed</span>
</div>
</div>
</div>
<div id="deliveryAddressType" class="home-wrap topTwoButtons" style="margin-top: 20px;">
<div class="col-half">
<div class="inline-button">
<input type="radio" class="delivery-address-type" value="Residential" name="delivery-address-type" id="delivery-address-type-residential">
<label for="delivery-address-type-residential">RESIDENTIAL</label> <span>text removed</span>
</div>
</div>
<div class="col-half">
<div class="inline-button">
<input type="radio" class="delivery-address-type" value="Business" name="delivery-address-type" id="delivery-address-type-business">
<label for="delivery-address-type-business">BUSINESS</label>
</div>
</div>
</div>
</fieldset>
</div>
<div id="package-step06" class="clearBoth teal-background flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 6:</strong> Enter your contact details</legend>
<div class="your-details">
<label for="your-first-name">Your first name*</label>
<input type="text" name="your-first-name" id="your-first-name" required>
<label for="your-surname">Your surname*</label>
<input type="text" name="your-surname" id="your-surname" required>
<label for="your-email">Your email address*</label>
<input type="email" name="your-email" id="your-email" required>
<label for="your-phone">Your phone number*</label>
<input type="tel" name="your-phone" id="your-phone" required>
</div>
</fieldset>
</div>
<div id="package-step07" class="clearBoth flag-strip">
<fieldset class="package-section-title side-padding max-width-1000">
<legend><strong>Step 7:</strong> Enter your event details</legend>
<div class="your-details">
<div class="question-with-note">
<label for="event-date">Date of event*</label>
<input type="text" class="datepicker" name="event-date" id="event-date" required>
<a class="info-link" href="#">Information</a>
<div class="question-note">
<p>Weekly rental period . . .</p>
</div>
</div>
<label for="event-end-date">End date (if event is more than one day)</label>
<input type="text" class="datepicker" name="event-end-date" id="event-end-date">
<label for="event-postcode">Delivery postcode*</label>
<input type="text" name="event-postcode" id="event-postcode" required>
<div class="delivery-specific-field">
<div class="question-with-note">
<label for="delivery-address">Delivery address*</label>
<textarea name="delivery-address" id="delivery-address"></textarea>
<a class="info-link" href="#">Information</a>
<div class="question-note">
<p>This should be an address . . .</p>
</div>
</div>
<label for="event-contact">Contact name text removed</label>
<input type="text" name="event-contact" id="event-contact">
</div>
<label for="additional-comments">Any additional comments/requirements?</label>
<p><small>For example text removed</small></p>
<textarea name="additional-comments" id="additional-comments"></textarea>
<p>By sending your enquiry you agree to our <a href="/terms-conditions/" target="_blank" rel="noopener">terms and conditions</a>.</p>
<input type="submit" value="Send enquiry">
</div>
</fieldset>
</div>
</form>
<?php endif; ?>
</div>
</div><!-- .entry-content -->
</article><!-- #post-## -->
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->
<?php get_footer();
我自己没有编辑过代码,但我知道该表单之前可以运行。 PHP 是不是少了一小块?任何帮助将不胜感激。
致以最美好的祝愿,
兰克斯
我将 mail() 函数更改为 wp_mail(),一切都恢复正常了。