Select Posts from checkboxes
-
Hi,
I made a form which shows all posts of a category and these posts should be able to be selected by checkboxes. I found a php code here on the Support site, but it was ment for dropdown-Selections, which shows the titles of the posts in the option fields.
The Posts are correctly shown on my site and I’m also able to check the checkboxes, but when I send the form, the names don’t appear in the submitted e-mail.
This is the code (functions.php), that I found:
wpcf7_add_shortcode('postdropdown', 'createbox', true); function createbox(){ global $post; $args = array('numberposts' => 0, 'category' => 5 ); $myposts = get_posts( $args ); $output = "<select name='cursus' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option></option>"; foreach ( $myposts as $post ) : setup_postdata($post); $title = get_the_title(); $output .= "<option value='$title'> $title </option>"; endforeach; $output .= "</select>"; return $output; }
and this is my Version:
<?php wpcf7_add_shortcode('postdropdown', 'createbox', true); function createbox(){ global $post; $args = array('numberposts' => 0, 'category' => 3 ); $myposts = get_posts( $args ); $output = '<table id="mietwohnungen"> <tr> <th> </th> <th width="150">Ort</th> <th width="150">Fotos</th> <th width="360">Beschreibung</th> <th width="100">Grösse</th> <th>Euro</th> </tr>'; foreach ( $myposts as $post ) : setup_postdata($post); $content = get_the_content(); $title = get_the_title(); $ort = get_post_meta($post->ID, 'Ort', true); $groesse = get_post_meta($post->ID, 'Gr??e', true); $Kaufpreis = get_post_meta($post->ID, 'Kaufpreis', true); $output .= "<tr><td> <input type='checkbox' name='$title' /> </td> <td>$ort</td> <td colspan='2'>$content</td> <td>$groesse</td> <td>$Kaufpreis</td> </tr>"; endforeach; return $output; $output .= '</table>'; } ?>
I put the shortcode [postdropdown mietwohnungen] in the contact form and [mietwohnungen] in the mailtemplate.
I’m spending hours in solving this special problem, but I still can’t get it fixed, unfortunately I’m no PHP expert.
Thanks,
Christiane
- The topic ‘Select Posts from checkboxes’ is closed to new replies.