I am trying to add some custom code to my Contact Form 7 for a career form and make it work with the pipe integrated system.
I have created a shortcode that get my custom post type career
and generate a select menu based on Contact Form 7 syntax.
My goal is to be able to make the pipe system working witin my shortchode.
First, I added a filter to be able to generate all the shortcodes inside Contact Form 7
I inserted this code in functions.php
:
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );
return $form;
}
After this, I went in my Administration and edited the Contact Form 7 with this part of code :
<div class="form-group">
<label for="residence" class="required">Please select</label>
[batisseurs_jobs]
</div>
This select will loop on the custom post type career and display the job list in a select. The code looks like this so far :
public function batisseurs_emplois( $atts, $content ) {
// args
$args = array(
'post_type' => 'career',
'orderby' => 'menu_order',
'order' => 'ASC',
'ignore_sticky_posts' => 1,
);
$query = new WP_Query( $args );
if ( ! $query->have_posts() ) {
return '';
}
$html = array();
$html[] = sprintf(
'<option value>%s</option>',
__("---", "wheels")
);
while ( $query->have_posts() ) {
$query->the_post();
// ACF
$localisations = get_field('disponibilite_du_poste');
for ($i=0; $i < sizeof($localisations); $i++) {
$localisation = $localisations[$i];
$html[] = sprintf(
'<option value="%s|%s">%s</option>',
get_the_title($query->ID) . ' - ' . $localisation['nom_de_la_residence'],
$localisation['contact_principal'],
get_the_title($query->ID) . ' - ' . $localisation['nom_de_la_residence']
);
}
}
wp_reset_postdata();
return '<label><span class="wpcf7-form-control-wrap menu-302"><select name="menu-302" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" id="residence" aria-required="true" aria-invalid="false">' . implode( '', $html ) . '</select></span></label>';
}
The output HTML looks like this :
<select name="menu-302" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" id="residence" aria-required="true" aria-invalid="false">
<option value="">---</option>
<option value="Job title - City|[email protected]">Job title - City</option>
<option value="Job title - City|[email protected]">Job title - City</option>
</select>
You can see that I am trying to use the pipe system inside the shortchode.
But when I write in the To: field [menu-302] I get an error because it try to send to an unspecified value I guess.
I think so because when I create the same thing directly in the Contact Form7 editor, the Email / pipe email is not displayed in the output HTML.
Does some 1 know how I could get it working or I am better to just do raw PHP ?