javascript - Call Java Script function if $POST or cookie is emtpy? -


i want call java script function called expandregisterform() if conditions apply:

    if ( isset( $_post['billing_first_name'] ) && empty( $_post['billing_first_name'] ) ) {         //call expandregisterform()     }      if ( isset( $_post['billing_last_name'] ) && empty( $_post['billing_last_name'] ) ) {         //call expandregisterform()     }       if ( isset( $_post['billing_phone'] ) && empty( $_post['billing_phone'] ) ) {         //call expandregisterform()     }      if ( isset( $_post['billing_address_1'] ) && empty( $_post['billing_address_1'] ) ) {         //call expandregisterform()     }      if ( isset( $_post['billing_postcode'] ) && empty( $_post['billing_postcode'] ) ) {         //call expandregisterform()     }      if ( isset( $_post['billing_city'] ) && empty( $_post['billing_city'] ) ) {         //call expandregisterform()     }      if ( isset( $_post['billing_state'] ) && empty( $_post['billing_state'] ) ) {         //call expandregisterform()     } 

this js function expands register formular. , should expanded if there not entered. question is, how can call js function?

i tried code in header.php , function.php both variations of calling js function:

  1. echo <script>expandregisterform()</script>;
  2. ?><script>expandregisterform();</script><?php

none of them working. because inserted code in header.php , function.php?

should maybe insert code somewhere else? if yes, where? have wordpress site know.

my second thought cookie. if user presses button, set cookie 1 hour flow time. , if cookie set, call expandregisterform() js function. same here. how , call function?

would happy help! kind regards

since called expandregisterformon header.php, being called before form function supposed expand created in dom. may can try this. on header.php

 $expand_form = false; if ( isset( $_post['billing_first_name'] ) && empty( $_post['billing_first_name'] ) ) {     $expand_form = true; } ... 

on footer.php

if($expand_form ==true) {     echo "<script>expandregisterform()</script>"; } 

i have point out though not best way this. ideally want validate fields javascript before submitted.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -