cf_form_ajaxsetup

The Caldera Forms cf form ajaxsetup function.

Description

cf_form_ajaxsetup( $form ); 

Parameters (1)

0. $form
The form.

Usage

  1. if ( !function_exists( 'cf_form_ajaxsetup' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-forms/includes/ajax.php'; 
  3.  
  4. // The form. 
  5. $form = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cf_form_ajaxsetup($form); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/ajax.php  
  1. function cf_form_ajaxsetup($form) { 
  2. if( !isset( $form['custom_callback'] ) ) { 
  3. $form['custom_callback'] = null; 
  4. ?> 
  5. <div class="caldera-config-group"> 
  6. <fieldset> 
  7. <legend><?php echo esc_html__( 'Ajax Submissions', 'caldera-forms'); ?></legend> 
  8. <div class="caldera-config-field"> 
  9. <input type="checkbox" id="caldera-forms-enable_ajax" value="1" name="config[form_ajax]" class="field-config"<?php if(isset($form['form_ajax'])) { echo ' checked="checked"'; } ?>> 
  10. <label for="caldera-forms-enable_ajax"><?php echo esc_html__( 'Enable Ajax Submissions. (No page reloads)', 'caldera-forms'); ?></label> 
  11. </div> 
  12. </fieldset> 
  13. </div> 
  14.  
  15.  
  16. <div class="caldera-config-group"> 
  17. <fieldset> 
  18. <legend><?php esc_html_e( 'Custom Callback', 'caldera-forms'); ?></legend> 
  19. <div class="caldera-config-field"> 
  20. <input id="caldera-forms-custom_callback" type="checkbox" onclick="jQuery('#custom_callback_panel').toggle();" value="1" name="config[has_ajax_callback]" class="field-config"<?php if(isset($form['has_ajax_callback'])) { echo ' checked="checked"'; } ?>><label for="caldera-forms-custom_callback"><?php echo esc_html__( 'Add a custom Javascript callback handlers on submission.', 'caldera-forms'); ?></label> 
  21. </div> 
  22. </fieldset> 
  23.  
  24. </div> 
  25.  
  26. <div id="custom_callback_panel" <?php if(empty($form['has_ajax_callback'])) { echo 'style="display:none;"'; } ?>> 
  27.  
  28. <div class="caldera-config-group"> 
  29. <fieldset> 
  30. <legend> 
  31. <?php esc_html_e( 'Inhibit Notices', 'caldera-forms'); ?> 
  32. </legend> 
  33. <div class="caldera-config-field"> 
  34. <input id="caldera-forms-inhbit_notices" type="checkbox" value="1" name="config[inhibit_notice]" class="field-config"<?php if(isset($form['inhibit_notice'])) { echo ' checked="checked"'; } ?>><label for="caldera-forms-inhbit_notices"><?php esc_html_e("Don't show default alerts (success etc.)", 'caldera-forms'); ?></label> 
  35. </div> 
  36. </fieldset> 
  37. </div> 
  38.  
  39.  
  40. <div class="caldera-config-group" style="width:500px;"> 
  41. <fieldset> 
  42. <legend> 
  43. <?php esc_html_e( 'Callback Function', 'caldera-forms'); ?> 
  44. </legend> 
  45. <div class="caldera-config-field"> 
  46. <input id="caldera-forms-custom_callback" type="text" value="<?php echo $form['custom_callback']; ?>" name="config[custom_callback]" class="field-config block-input" aria-describedby="caldera-forms-custom_callback-desc"> 
  47. <p class="description" id="caldera-forms-custom_callback-desc"> 
  48. <?php esc_html_e('Javascript function to call on submission. Passed an object containing form submission result.'); ?> <a href="#" onclick="jQuery('#json_callback_example').toggle();return false;"><?php esc_html_e( 'See Example', 'caldera-forms' ); ?></a> 
  49. </p> 
  50. <pre id="json_callback_example" style="display:none;"><?php echo htmlentities(' 
  51. {  
  52. "data": { 
  53. "cf_id" : "200", // Form Entry ID 
  54. "my_var" : "custom passback variable defined in variables tab",  
  55. "my_other" : "another custom passback variable",  
  56. "get_var" : "GET variable from embedded page",  
  57. "more_var" : "another GET variable",  
  58. },  
  59. "url" : "redirect url. only included if redirection is needed. e.g redirect processor",  
  60. "result" : "Sent. Thank you, David.", // result text after magic tag render. 
  61. "html" : "<div class=\"alert alert-success\">Sent. Thank you, David.</div>",  
  62. "type" : "complete",  
  63. "form_id" : "CF551d804e0d72e",  
  64. "form_name" : "Example Form",  
  65. "status" : "complete" 
  66. }'); ?> 
  67. </pre> 
  68. </div> 
  69. </fieldset> 
  70. </div> 
  71.  
  72.  
  73.  
  74.  
  75. </div> 
  76.  
  77. <div class="caldera-config-group"> 
  78. <fieldset> 
  79. <legend> 
  80. <?php echo esc_html__( 'Multiple Ajax Submissions', 'caldera-forms'); ?> 
  81. </legend> 
  82. <div class="caldera-config-field"> 
  83. <input for="caldera-forms-multi-ajax" type="checkbox" value="1" name="config[form_ajax_post_submission_disable]" class="field-config"<?php if(isset($form['form_ajax_post_submission_disable'])) { echo ' checked="checked"'; } ?>><label for="caldera-forms-multi-ajax"><?php esc_html_e( 'If set, form can be submitted multiple times with out a new page load.', 'caldera-forms'); ?></label> 
  84. </div> 
  85. </fieldset> 
  86. </div> 
  87. <?php