Title: Validation Fields
Last modified: January 31, 2020

---

# Validation Fields

 *  Resolved [deroen](https://wordpress.org/support/users/deroen/)
 * (@deroen)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/)
 * Hello i use the CMB2 Tool and try to solve the Problem to Validate 2 Fields.
   (
   The same Question is alsos Here: [https://wordpress.stackexchange.com/questions/356633/cmb2-toolkit-compare-2-dates-and-validate-the-time](https://wordpress.stackexchange.com/questions/356633/cmb2-toolkit-compare-2-dates-and-validate-the-time),
   can i upload here pictures like in wordpress.stackexchange.com ?)
 * Both are fomr type: ‘text_date’, ” and both are working very well. One of them
   are the Start-Time and the other is the Ending-Time. What i need is to compare
   both Fields after i click on Publish.
    I have wrote this Code for Testing the
   function:
 * = = = = = = = = = = = = = = =
 * add_action(‘admin_footer’, ‘event_post_validation’);
    function event_post_validation(){
   if ($_SERVER[‘PHP_SELF’] != ‘/wp-admin/post-new.php’) {return;} //here comes 
   the inputs from the user to check $RNnumber = mt_rand(5, 15); echo ‘<script> 
   jQuery( “form#post #publish” ).hide(); jQuery( “form#post #publish” ).after(“
   <input type=\’button\’ value=\’Publish/Update\’ class=\’sb_publish button-primary\’/
   ><span class=\’sb_js_errors\’></span>”); jQuery( “.sb_publish” ).click(function(){//
   first problem: after click -> check again the value / call again this function//
   second problem: get the userinput and grab them to check the value before it 
   gets updated to the webseite frontend var error = false var numberofphp = ‘.$
   RNnumber.’; var anumbertest = 99; if( ‘.$RNnumber.’ <= “8”) { jQuery(“.sb_js_errors”).
   text(“less than 8: ‘.$RNnumber.'”); } else if( ‘.$RNnumber.’ >= “8”) { jQuery(“.
   sb_js_errors”).text(“greater than 8: “+ numberofphp +” “); } else if (!error){
   jQuery( “form#post #publish” ).click(); } else { jQuery(“.sb_js_errors”).text(“
   There was an error on the page and therefore this page can not yet be published.”);}});
   </script>’; }
 * = = = = = = = = = = = = = = = = = = = = = = = =
    This is just a Test because 
   i have there 2 Problems which i can not solve: First is: When the user writes
   the wrong Dates, he has to write all Fields again because the click-function 
   triggers just one time. I do not how to solve that. The second Problem is: How
   do i get the userinputs without sending them to the Database? I am now realy 
   confused how to solve that like the “types: requried or min” which you made. 
   I hope i will finish this Task and afterwards you can put the code to the CMB2-
   Page for other people Thank you
    -  This topic was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This topic was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This topic was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This topic was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12385721)
 * Just verifying quick, you were around a week or two back with a date comparison
   issue and how an end date field wasn’t meant to be able to select anything earlier
   than a start date field, right?
 *  Thread Starter [deroen](https://wordpress.org/support/users/deroen/)
 * (@deroen)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12386096)
 * yes i asked that question. After that i tried to code this “jquery solution”.
   But i am not professional and is hard for Beginners.
    -  This reply was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This reply was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This reply was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
    -  This reply was modified 6 years, 4 months ago by [deroen](https://wordpress.org/support/users/deroen/).
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12386875)
 * **When the user writes the wrong Dates, he has to write all Fields again because
   the click-function triggers just one time. I do not how to solve that.**
 * When is this happening? Like when clicking publish/update and things aren’t valid
   in some way and all the fields are empty again after the page refresh? Something
   else?
 * **How do i get the userinputs without sending them to the Database? I am now 
   realy confused how to solve that like the “types: requried or min” which you 
   made.**
 * You should be able to use jQuery to retrieve text input values, if you’re wanting
   to do some validation before pressing publish/update. `$('#myinput').val()` would
   retrieve whatever is in the input.
 *  Thread Starter [deroen](https://wordpress.org/support/users/deroen/)
 * (@deroen)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12388532)
 * Yes. When i click on “publish/update” the function will get called just one time.
   Afterwards when i click on “publish/update” it makes nothing unless i refresh
   the whole page and fill all the Fields again.
 * Thank for ” $(‘#myinput’).val() ” i think i have found there a way here to solve
   that: [https://stackoverflow.com/questions/41622828/validating-email-through-php-and-jquery](https://stackoverflow.com/questions/41622828/validating-email-through-php-and-jquery)
   
   Looks very hard but i try to solve that somehow. I will post it later here the
   code or shall i post it as picture? Maybe you can look for that?
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12389676)
 * Given that this is largely outside the scope of the core plugin support, it’d
   be best to have you post any followup.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Validation Fields’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/validation-fields/#post-12389676)
 * Status: resolved