2

ユーザーのチェックボックスの選択 (Wordpress で作成) を収集し、結果をメールで返すフォームを作成しました (パーツは省きました)。

ハードウェアの選択にチェックを入れて送信すると、電子メールは正常に送信されますが、アクセサリのいずれかにチェックを入れて送信をクリックすると、404 ページに移動します。

誰でもエラーがどこにあるかを見ることができますか? チェックボックスと結果の 2 つのセットを同じ方法で作成しましたが、エラーの場所がわかりません!

<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>
4

3 に答える 3

1

htmlspecialchars値の出力で使用を開始するには:

<input type="checkbox" name="accessories[]" value="<?php the_title(); ?>">
<input type="checkbox" name="accessories[]" value="<?php htmlspecialchars(the_title()); ?>">

Second : あなたformCheckは二度、

in <form id="customisesystem"> and `<input type="submit" />`.

1つだけ残しました。

3番目で最も重要です。

あなたが思うようにWPは機能しません。hook次の条件は、適切なas内でチェックする必要がありますinit

add_action('init', 'check_form');
function check_form(){
    if(isset($_POST['submit'])){ 
        // check form
        if (is_OK)
            // redirect to same page
            wp_redirect($my_url);
        else
            // continue to show the form to allow modification
    }
}

4 番目expects parameter 1 to be string, array given: あなたのページには、 php 関数によるメッセージ エラーが表示されます。だからこれをしてください:

行 1452 と 968 に移動し、これらの関数に渡された変数のデバッグを行い、それらが何であるかを示します。

var_dump()

おそらくあなたは次のようなことをしています:

trim($_POST['accessories']);

しかし、次のようにする必要があります。

foreach ($_POST['accessories'] as $val)
{
    $new_val = $val;
    $new_val = trim($new_val);
    $new_val = strip_tags($new_val);

    // more ....
}
于 2013-02-12T13:54:09.637 に答える
1

上記のコードとは直接関係がないと思います(または、この動作に影響する CMS 内部関数への制約関数呼び出しとしてエラーが呼び出されるだけです)が、投稿されたサイトを見て試してみました.

すべてが正常な場合、URL は 404 エラーと同じです (両方とも200 OKHTTP ヘッダーで出力されます。これは奇妙で、実行しているシステム全体の問題のようです。 404 ページでいくつかの PHP エラーが検出され、最初に出力されます。

警告: trim() は、パラメーター 1 が文字列であると 想定し、 1452 行目の/home/teamwork/public_html/clients/rogue/wp-includes/query.phpで指定された配列です警告: strip_tags() は、パラメーター 1 が文字列であり、配列が指定されていると想定します/home/teamwork/public_html/clients/rogue/wp-includes/formatting.php968 行目


おそらく、これらの WordPress 関数が呼び出されます。どこで/いつ呼び出されるかを正確にデバッグできますか?

CMS が正しいビューをレンダリングする代わりにエラー モードに入る可能性がありますか?

于 2013-02-12T13:59:38.730 に答える
1

この問題に 2 日間費やした結果、最も苛立たしい答えが見つかりました。チェックボックスの値が だったところをaccessories[]に変更するaccess[]と、うまくいきました。

理由はよくわかりませんが、値 var の長さでしょうか?

于 2013-02-12T15:57:44.637 に答える