Advertisement
bedas

CRED AJAX

Sep 15th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. CRED Submitting Forms via AJAX is possible with this slight JS script. Note that this does ONLY submit the form and NOT replace the form with the Post (show post). That is only partially possible and causes issues on Loops (View), there fore it did not make it to this Code snippet.
  2.  
  3. Download and add to your theme:
  4. http://malsup.github.com/jquery.form.js
  5.  
  6. Add to your Functions PHP:
  7.  
  8. wp_enqueue_script("jquery");
  9. wp_enqueue_script( 'jquery-form-js', get_template_directory_uri() . '/js/jquery.form.js', array('jquery'), '3.51.0-2014.06.20', true );
  10. In any SINGLE CRED form JS Editor:
  11.  
  12. jQuery(document).ready(function() {
  13.  
  14. jQuery('#cred_form_4988_1').ajaxForm(function() {
  15. alert("Thank you for your comment!");
  16. });
  17. });
  18. Replace #cred_form_4988_1 with the actual ID of the CRED Form you’ll see in your browser console asa in this:
  19.  
  20. <form enctype="multipart/form-data" id="cred_form_4988_1" class="cred-form cred-keep-original" action="/toolset/2015/07/08/ajax-edit/?cred-edit-form=4988&amp;_tt=1436396327" method="post">
  21. If you have MULTIPLE CRED FORMS (of same form), outputted in a Views Loop
  22. Means, you got x posts, and therefore x CRED Forms of same type,the ID of CRED is continuously increased by one, so the a above jQuery breaks. You should use here:
  23.  
  24. jQuery(document).ready(function() {
  25. jQuery("[id^=cred_form_1096]").ajaxForm(function() {
  26. alert("Thank you for your comment!");
  27. });
  28. });
  29. We use now ("[id^=PART_OF_ID]")
  30.  
  31. You can also seek for all elements which contain (*=) or end up with ($=) known part of ID/class/type.
  32. (example, id^, id*, id$)
  33.  
  34. DOC Links:
  35. http://malsup.com/jquery/form/#getting-started
  36. http://jsbin.com/qaxuledihi/edit?html,output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement