我创建了一个表单(我省略了部分),它收集用户的复选框选择(通过 Wordpress 创建)并将结果通过电子邮件发送给我。
当我勾选硬件选择并提交时,电子邮件正常,但是当我勾选任何附件并单击提交时,它会进入 404 页面。
谁能看到错误在哪里?我以同样的方式创建了两组复选框和结果,只是看不到错误在哪里!
<form id="customisesystem" name="enquiry" method="POST" onSubmit="return formCheck(this);" action="<?php echo the_permalink(); ?>">
<div id="customise-area">
<?php $posts = get_field('options');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div>
<p><?php echo the_field('description'); ?></p>
</div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="hardware[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
<div id="customise-area">
<?php $posts = get_field('accessories');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div>
<p><?php echo the_field('description'); ?></p>
</div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="accessories[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
<? if(isset($_POST['submit'])) {
$to = "rob@domain.com";
$header = 'From: rob@domain.com';
$subject = "Domain: Quotation";
$enquiry_first_name = $_POST['enquiryfirstname'];
$enquiry_last_name = $_POST['enquirylastname'];
$enquiry_title = $_POST['enquirytitle'];
$enquiry_organisation = $_POST['enquiryorganisation'];
$enquiry_address = $_POST['enquiryaddress'];
$enquiry_country = $_POST['enquirycountry'];
$enquiry_email_address = $_POST['enquiryemailaddress'];
$enquiry_telephone = $_POST['enquirytelephone'];
$enquiry_additional_comments = $_POST['enquiryadditionalcomments'];
$enquiry_product = get_the_title();
if(!empty($_POST['hardware'])) {
foreach($_POST['hardware'] as $check) {
$hardwareresults .= $check."\n";
}
}
if(!empty($_POST['accessories'])) {
foreach($_POST['accessories'] as $test) {
$accessoriesresults .= $test."\n";
}
}
$body = "You have a quote request from the website:
Quotation:
$enquiry_product
Hardware:
$hardwareresults
Accessories:
$accessoriesresults
Name: $enquiry_title $enquiry_first_name $enquiry_last_name
Type of organisation: $enquiry_organisation
Address: $enquiry_address, $enquiry_country
E-Mail: $enquiry_email_address
Tel: $enquiry_telephone
Comments: $enquiry_additional_comments
Kind regards";
mail($to, $subject, $body, $header);
echo "Thank you for your enquiry.";
} ?>
</form>