Advertisement
webreach

acf in cf7

May 10th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. //acf select on cf7
  2. //add shortcode to cf7
  3. function add_faculty_and_classes_options_to_cf7() {
  4.     wpcf7_add_form_tag( array( 'faculty_select', 'faculty_select*'), 'faculty_options', array( 'name-attr' => true ) );
  5. }
  6.  
  7. add_action( 'wpcf7_init', 'add_faculty_and_classes_options_to_cf7' );
  8.  
  9. //define shortcode
  10. function faculty_options( $tag ) {
  11.     $faculties = get_field('faculties', 'option', false);
  12.     $faculties = explode("\n", $faculties);
  13.     $faculties = array_map('trim', $faculties);
  14.     $output = "<select name='faculty_select' id='faculty_select'><option selected disabled>בחר פקולטה</option>";
  15.     if( is_array($faculties) ) {
  16.         foreach( $faculties as $faculty ) {
  17.             $output .= '<option value="' . $faculty . '">' . $faculty . '</option>';
  18.         }
  19.     }
  20.     $output .= "</select>";
  21.  
  22.     return $output;
  23. }
  24.  
  25.  
  26. //in cf7 add in form/mail
  27. [faculty_select*]
  28.  
  29.  
  30.  
  31.  
  32. // acf recipinet
  33. //in cf7 form
  34. <div style="display:none">[email* recipient-mail id:recipient-mail]</div>
  35.  
  36. //in cf7 mail tab "to"
  37. [recipient-mail]
  38.  
  39. // in code
  40. <?php $postRecipientField = get_field('course_recipient'); ?>
  41. <?php if ($postRecipient) {
  42.     $postRecipient = $postRecipientField;
  43. } else {
  44.     $postRecipient = 'xtra4@student.co.il';
  45. } ?>
  46. <span style="display: none" id="acf-post-recipient"><?php echo $postRecipient ?></span>
  47.  
  48. <script>
  49.     jQuery(function ($) {
  50.         $(document).ready(function(){
  51.             $('#recipient-mail').val('<?php the_field('course_recipient'); ?>');
  52.         });
  53.     });
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement