0
我正在創建一個表單,將表單的詳細信息發送到我的電子郵件。如何獲得wordpress的自定義提交值並將其分配給變量?
我的自定義字段是:
我function.php
function getHotel_contact_number() {
global $wp_query;
$postid = $wp_query->post->ID;
$getHotel_contact_number = get_post_meta($postid, 'hotel_contact_number', true);
$getHotel_contact_number;
}
我的形式是:
<?PHP
$errors = array();
if (isset($_POST["submit"])) {
$to = "[email protected]";
$subject = "This is my subject";
$hotel = get_permalink();
$hotel_contact_nmbr = getHotel_contact_number();
$headers = array('From: '.$_POST['sendername'].' <'.$_POST['senderEmail'].'>');
//Check the name and make sure that it isn't a blank/empty string.
if(empty($sender)){
//Blank string, add error to $errors array.
$errors['sendername'] = "Please enter your name!";
}
if(empty($senderEmail)){
//Blank string, add error to $errors array.
$errors['senderEmail'] = "Please enter your email!";
}
$mailBody = "<h3>Hotel Details</h3><br/>
$hotel<br/>
$hotel_contact_nmbr<br/>"
$mail_sent = wp_mail($to, $subject, $mailBody, $headers);
}
if ($mail_sent) { ?>
<h1 style="color: #007f00;">Request sent.</h1>
<?php
} else {
?>
<form id="" name="" action="<?php echo get_permalink(); ?>" method="post">
<div class="label-input-wrapper">
<div class="form-label">Name</div>
<div class="form-input">
<input type="text" name="sendername" value="<?PHP if(!empty($errors)) { echo $sender;} ?>" />
<div class="error-msg">
<?php if(isset($errors['sendername'])) { echo '<span style="color: red">'.$errors['sendername'].'</span>'; } ?>
</div>
</div>
</div>
<div class="label-input-wrapper">
<div class="form-label">E-Mail</div>
<div class="form-input">
<input type="email" name="senderEmail" pattern="[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$" required value="<?PHP if(!empty($errors)) { echo $senderEmail;} ?>" />
<div class="error-msg">
<?php if(isset($errors['senderEmail'])) { echo '<span style="color: red">'.$errors['senderEmail'].'</span>'; } ?>
</div>
</div>
</div>
<input type="submit" value="Submit" name="submit">
</form>
<?php
}
?>
但是,當表單提交我我只得到一個空白值爲hotel contact number
。我做錯了什麼?表單提交時如何獲得正確的自定義提交值?
無論如何,它的工作正常,如果我使用隱藏的領域,因爲我提到here: 看看我提到隱藏領域的問題的底部區域。用下面的代碼
再次感謝@Bhumi沙阿..我忘記這些小東西.. – 2014-10-10 12:12:58