登録

2016-04-18 20 views
0


登録

会社オプションでは、2つの追加フィールドがあります。ラジオボタンでプライベートと企業の間を切り替えることができ、関連するフィールドが表示されます。

問題:フォームを(プライベートユーザーとして)記入して間違えた場合は、フォームを再読み込みし、エラーがどこにあるかを表示してください(これは問題ありません)。

残念ながら、リロード後、フォームにはすべてのフィールド(会社フィールドも追加されたフィールド)が読み込まれます。だから、正しい行動を取り戻すためには私と私の間で2回クリックする必要があります。

どうすればこの問題を解決できますか?私はこのエラーを再ロードした後、フォームを最初に表示することを意味します。

私は、これは、この責任のコードであることを確認してください、しかし、試してみましょうしないでください:

add_filter('woocommerce_registration_errors', 'rs_registration_form_validation', 10, 3); 
function rs_registration_form_validation($reg_errors, $sanitized_user_login, $user_email) 
{ 
    global $woocommerce; 

    $company_fields_required = (!empty($_POST['registration_type']) && 'company' === $_POST['registration_type']); 
    $shipp_to_different_address = (!empty($_POST['register_ship_to_different_address']) && 1 == $_POST['register_ship_to_different_address']); 

    $errors = false; 
    $fields = rs_registration_form_fields(); 
    if ($shipp_to_different_address) { 
     $fields += rs_registration_form_fields_address(); 
    } 

    if (!$company_fields_required) { 
     unset($fields['billing_company']); 
     unset($fields['billing_nip']); 
    } 

    //Validate required 
    foreach ($fields as $field => $settings) { 
     if (false === isset($settings['required']) || true === $settings['required']) { 
      if (empty($_POST[$field])) { 
       $errors = true; 
       wc_add_notice('Pole: <strong>'.$settings['label'].'</strong> jest wymagane.', 'error'); 
      } 
     } 
    } 

    if ($errors) { 
     return new WP_Error('registration-error', 'Proszę poprawić błędy w formularzu'); 
    } 

    return $reg_errors; 
} 

add_action('woocommerce_created_customer', 'rs_registration_form_submit'); 
function rs_registration_form_submit($user_id) 
{ 
    $fields = rs_registration_form_fields(); 
    $fields += rs_registration_form_fields_address(); 

    foreach ($fields as $field => $settings) { 
     if (isset($_POST[$field]) && !empty($_POST[$field])) { 
      update_user_meta($user_id, $field, $_POST[$field]); 
     } 
    } 
} 

add_filter('register_form', 'rs_registration_form'); 
function rs_registration_form() 
{ 
    $fields = rs_registration_form_fields(); 

    include '_rs_registration_form.php'; 
} 

add_filter('register_form_address', 'rs_registration_form_address'); 
function rs_registration_form_address() 
{ 
    $fields = rs_registration_form_fields_address(); 

    include '_rs_registration_form.php'; 
} 

add_filter('woocommerce_edit_address_slugs', 'rs_fix_address_slugs'); 
function rs_fix_address_slugs($slugs) 
{ 
    $slugs['billing'] = 'billing'; 
    $slugs['shipping'] = 'shipping'; 

    return $slugs; 
} 

function rs_rejestracja_url() 
{ 
    return get_permalink(244); 
} 

function rs_logowanie_url() 
{ 
    return get_permalink(20); 
} 

function rs_show_checkout_progress_bar($step = '') 
{ 
    include '_checkout_progress_bar.php'; 
} 

function rs_order_form_buttons() 
{ 
    include '_order_form_buttons.php'; 
} 

add_filter('woocommerce_get_checkout_url', 'rs_get_checout_url'); 
function rs_get_checout_url($url) { 
    if (is_user_logged_in()) { 
     $url .= '#step1'; 
    } 

    return $url; 
} 

include 'src/RS_Search.php'; 

答えて

0

私はWooCommerceを知らないが、私はので、これらのラインのエラー結果を考える:

$company_fields_required = (!empty($_POST['registration_type']) && 'company' === $_POST['registration_type']); 

if (!$company_fields_required) { 
    unset($fields['billing_company']); 
    unset($fields['billing_nip']); 
} 

あなたが「プライベート」フォームを提出しており、検証があなたのフィールドを、失敗した後、再度読み込まれます。 $ _POST変数の中でregistration_typeが何らかの形で 'company'に設定されているのでしょうか?関数の最初に$ _POST ['registration_type']をprint_rすればテストできます。そうでない場合は、これまでのところ私には意味があるので、別の関数でバグが起こっていることは間違いありません。

編集:あなたのコードをもう一度見て、投稿された機能のどれもが誤動作の原因ではないと思います。最初の機能は、投稿された値の一部が欠落しているかどうかをチェックし、「やあ、ここではエラーです」と言うだけです。後であなたのHTMLに表示されるフィールドを担当する別の機能が必要です。私はあなたがこの機能を見つける必要があると思います。

+0

ok。ここに登録フォームのテンプレートのコードです...これから何かを推論できますか? http://paste.ofcode.org/rd9Z4VUXjuiEeLBAQnRtxT – Pat

+0

はい、できると思います。カスタムフィールドは、ユーザー名、パスワードなどの入力後に表示されることがあります。これは、それらがフックwoocommerce_register_formまたはregister_formのいずれかで挿入されていることを意味します。作成してカスタムフィールドを担当する関数は、これらの2つのフックのいずれかを使用する必要があります。あなたは今、適切な機能を見つけることができますか? – Tim