You won’t be able to insert forms with do_shortcode, but you can use the following work-around to add Contact forms anywhere in your templates:
- Create a new Page, and insert a Contact form in the page.
- Note that Page’s ID
- In your template, add the following code:
<?php
query_posts( array( 'page_id' => 123 ) ); // ID of the page including the form
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile; endif;
wp_reset_query();
?>
Thread Starter
Chris
(@comradeseidl)
Jeremy,
Thanks, I have successfully implemented this solution. While testing it I found that the default subject line of the email is now the name of the page where I placed the contact form. Unfortunately I need the subject to remain equal to the post title where this contact form will be displayed; is there a way to do this?
Previous to updating Jetpack and WordPress to their newest versions, I was using do_shortcode() without any problems. Are there plans to make this usability available again?
Thanks.
Thread Starter
Chris
(@comradeseidl)
I was able to implement a solution for forcing the subject line to be what I want it to be (in this case, the title of the post on whose template file I am placing the contact form).
First, hook the custom subject function into the Grunion Contact Form filter:
add_filter('contact_form_subject', 'product_contact_subject');
Now, the function:
function post_contact_subject($subject) {
$url = $_SERVER['HTTP_REFERER'];
//Create an array divided by the base url. This example assumes that the post slug immediately follows the root domain. Change this to match your permalink structure.
$arr = explode(get_site_url() . '/', $url);
//Make sure that the array has at least two elements.
if (count($arr) < 2)
return $subject;
//Get the slug and remove the query string and any trailing slash if it exists.
$slug = str_replace('/', '', $arr[1]);
$slug = preg_replace('/\?.*/', '', $slug);
//Get the post id based on the slug.
$id = slug_to_id($slug);
//title
$title = get_the_title($id);
//Return the custom title
return $title;
}
Now, the function for getting a post’s ID from its slug:
function slug_to_id($slug, $type = 'post') {
$args=array(
'name' => $slug,
'post_type' => $type,
'post_status' => 'publish',
'showposts' => 1,
'caller_get_posts'=> 1
);
$my_posts = get_posts($args);
if( $my_posts ) {
return $my_posts[0]->ID;
} else {
return 0;
}
}
I hope that this helps anybody else with this problem.
Hi Jeremy and Comrade, I have this problem too. I followed Jeremy’s advice and used a page with a Jetpack form on it. The form still doesn’t seem to be functioning–neither email nor Feedback.
I have another Jetpack form on a different page which saves in Feedback just fine (no email sent, but I think that’s a server problem).
Here are the pages in question:
@tj Kelly – this thread is outdated and already marked resolved. Please start your own thread per the forum guidelines –
http://codex.ww.wp.xz.cn/Forum_Welcome#Where_To_Post
You can do so here:
http://ww.wp.xz.cn/support/plugin/jetpack#postform
Sorry, I didn’t notice the resolved status. Thank you
The problem was fixed in this commit. We’ll include the fix in the next Jetpack release.