これまでに何度も尋ねられたことは分かっていますが、実際にはすべての質問から使用できる決定的な回答はありませんでした。
私の$_POST
配列は、そのフォームの値を明確に選択したときに、自分の選択した要素を自分のフォームで受け取ったことがないようです。
私のようなWordPressのテーマにコンタクトフォームを持っている:
<form method="post" id="contactform" name="contactform" class="contact-form-native" action="<?php echo get_template_directory_uri() ?>/mail/contact.php">
<div class="col-md-6 margin-15">
<div class="form-group">
<input type="text" id="name" name="name" class="form-control input-lg" placeholder="<?php _e('Name*','framework'); ?>">
</div>
<div class="form-group">
<input type="email" id="email" name="email" class="form-control input-lg" placeholder="<?php _e('Email*','framework'); ?>">
</div>
<div class="form-group">
<input type="text" id="phone" name="phone" class="form-control input-lg" placeholder="<?php _e('Phone','framework'); ?>">
<input type ="hidden" name ="image_path" id="image_path" value ="<?php echo get_template_directory_uri() ?>">
<input id="admin_email" name="admin_email" type="hidden" value ="<?php echo $admin_email; ?>">
<input id="subject" name="subject" type="hidden" value ="<?php echo $subject_email; ?>">
</div>
<div class="form-group">
<select id="event_select" name="event_select" class="form-control">
<option disabled selected value> -- select the event -- </option>
<?php
$args = array(
// Arguments for your query.
'post_type' => 'event',
'meta_query' => array(
'start_date_clause' => array(
'key' => 'imic_event_start_dt',
'value' => date("Y-m-d", strtotime('first day of January '.date('Y-m-d'))),
'compare' => '>'
),
),
'orderby' => 'start_date_clause',
'order' => 'ASC'
);
// Custom query.
$query = new WP_Query($args);
// Check that we have query results.
if ($query->have_posts()) {
// Start looping over the query results.
$count = 0;
while ($query->have_posts()) {
$query->the_post();
echo '<option value="' . $count . '">' . date('jS M', strtotime(get_post_meta(get_the_ID(),'imic_event_start_dt',true))) . " - " . date('jS M', strtotime(get_post_meta(get_the_ID(),'imic_event_end_dt',true))) . "</option>";
$count++;
}
}
?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea cols="6" rows="7" id="comments" name="comments" class="form-control input-lg" placeholder="<?php _e('Message','framework'); ?>"></textarea>
</div>
</div>
<div class="col-md-12">
<input id="submit" name="submit" type="submit" class="btn btn-primary btn-lg pull-right" value="<?php _e('Submit now!','framework'); ?>">
</div>
</form>
この後、contact.php
で処理されます:
// - grab wp load, wherever it's hiding -
include "../../../../wp-config.php";
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$event_select = $_POST['event_select'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
私は、私は次のエラーを取得するフォームを送信する場合:
Notice: Undefined index: event_select in /homepages/5/d586424128/htdocs/wp-content/themes/NativeChurch/mail/contact.php on line 13
なぜ私は選択フィールドが存在しないのかを頭に浮かべることはできません$ _POST変数にENTと私は間違いなくこのような選択ルックスのための理由は、私のソース選択ボックス内の各オプションの値を持っている:いくつかのJavaScriptを取得があるように、その周りにいくつかの掘削は思わ
<select id="event_select" name="event_select" class="form-control">
<option disabled="" selected="" value=""> -- select the event -- </option>
<option value="0">16th Feb - 23rd Feb</option>
<option value="1">27th Feb - 5th Mar</option>
<option value="2">20th Mar - 26th Mar</option>
<option value="3">20th Apr - 26th Apr</option>
<option value="4">8th May - 14th May</option>
<option value="5">15th Jun - 25th Jun</option>
<option value="6">7th Aug - 14th Aug</option>
<option value="7">20th Sep - 25th Sep</option>
<option value="8">16th Oct - 23rd Oct</option>
</select>
'$ event_select = $ _POST ['event_select'];'何が起こるのでしょうか?私の推測では、あなたのフォームコードに 'event_select'コンボに関するいくつかの種類のエラーがあります。それをチェックするには、PHPコードをテストから取り出して、エラーがまだ発生するかどうかを確認してください。 –
フォームは、その行がなければ、エラーは 'wp-config'で' debug'をtrueに設定した場合のみ表示されます – user3574492
'if(!$ _ POST)exit;'これは問題です –