title: Validate form with 2 buttons independently with ajax and POST
body: <p>I have a pre checkout woocommerce custom login form via shortcode:</p>
  <pre><code>&lt;form method=&quot;post&quot; class=&quot;woocommerce-form&quot; id=&quot;login&quot; action=&quot;&lt;?php echo wc_get_checkout_url(); ?&gt;&quot;&gt;  
  &lt;p class=&quot;woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide&quot;&gt;
  &lt;label class=&quot;font-weight-medium mb-1&quot; for=&quot;reg_email&quot;&gt;E-mailadres&amp;nbsp;&lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
  &lt;input type=&quot;email&quot; class=&quot;woocommerce-Input&quot; name=&quot;email&quot; id=&quot;reg_email&quot; autocomplete=&quot;email&quot; 
  value=&quot;&lt;?php echo esc_attr( $postfield ); ?&gt;&quot;/&gt;
  &lt;/p&gt;
  &lt;div class=&quot;actions-container&quot;&gt;
  &lt;button type=&quot;submit&quot; name=&quot;method_guest&quot;&gt;Afrekenen als gast&lt;/button&gt;
  &lt;button type=&quot;submit&quot; name=&quot;method_account&quot;&gt;Account aanmaken&lt;/button&gt;
  &lt;/div&gt;
  &lt;input type=&quot;hidden&quot; value=&quot;nonce&quot;&gt;
  &lt;?php wp_nonce_field( '/bestellen/', 'nonce' ); ?&gt;  
  &lt;/form&gt; 
  </code></pre>
  <p>The form has an email field and 2 buttons, one button is to go to checkout as a guest, the other to go to checkout and create an account. I check if the user's email exists with <code>email_exists</code> and ajax via the remote jquery validation plugin method:</p>
  <pre><code>$(&quot;#login&quot;).validate({
    onfocusout: &quot;false&quot;,
      rules: {
          email: {
              required: true,
              email: true,
              remote: {
                  url: ajaxurl,
                  data: {
                      action: 'check_email'
                  },
                  type: &quot;post&quot;
               }
          }
      },
      messages: {
          email: {
              required: &quot;Enter an e-mailadres.&quot;,
              email: &quot;Enter a valid e-mailadres.&quot;,
              remote: &quot;Email already exists, login or continue as a guest.&quot;
          }
      },
       errorElement: &quot;span&quot;,
   errorClass: &quot;invalid&quot;,
  });
  </code></pre>
  <p>I would like to let the user continue as a guest with an existing email adres only when you click the guest checkout button. But this is not possible because of the validation for the create account button. I've been trying to edit my php function so that the response is always true (email doesn't exist) when the value from guest checkout button is set. This also doesn't work however. Is there way to let users continue with an existing email adres and keep the validation for the account button?
  PHP function:</p>
  <pre><code>function check_email(){
      $email = $_POST['email'];
  if (email_exists( $email ) &amp;&amp; isset($_POST['method_account'])){
  $response = false;
  } else {
  $response = true;
  }
          wp_send_json($response);
         wp_die();
      }
      
  add_action( 'wp_ajax_view_site_description', 'check_email' );
  add_action( 'wp_ajax_nopriv_view_site_description', 'check_email' );
  </code></pre>
  <p>Only way I can think of is now to place the guest checkout button outside of the form, but then the email adres won't be posted.</p>