Guest User

Untitled

a guest
Jun 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. $('.wpcf7-form').on('submit', function (e) {
  2. $.ajax({
  3. type: "post",
  4. dataType: "json",
  5. url: js_object.ajax_url,
  6. data: {
  7. action: "custom_reg_code",
  8. },
  9. success: function (response) {
  10. if (response.success) {
  11. $('#reg_code').val(response.data)
  12. }
  13. else {
  14. console.log('Something wrong')
  15. }
  16. },
  17. error: function (jqXHR, textStatus, errorThrown) {
  18. console.log('fail: ' + textStatus, errorThrown);
  19. },
  20. complete: function() {
  21. }
  22. })
  23. })
  24.  
  25. [dynamichidden custom_reg_code “CF7_custom_reg_code”]
  26.  
  27. function generateRandomString($length = 10) {
  28. return substr(str_shuffle(str_repeat($x='0123456789', ceil($length/strlen($x)) )),1,$length);
  29. }
  30.  
  31. function wpse306816_CF7_custom_reg_code() {
  32.  
  33. return date("Ymd") . generateRandomString();
  34. }
  35.  
  36. add_shortcode('CF7_custom_reg_code', 'wpse306816_CF7_custom_reg_code');
Add Comment
Please, Sign In to add comment