PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Replace standard comment form with a gravity form

  1. pbateman
    Member

    Is it possible to replace the standard comment form on single blog posts in WP with a gravity form?

    If so: how would I do this?

    Main reason why I ask is that the standard comment form takes you to an error page. I really like how gravity forms handles errors though.

    Additional question:
    If a gravity form is in the bottom of a website and someone forgets to put something in a required field then it automatically scrolls back up to the top of the page. So if that person does not scroll down it won't see that sending the form has not worked.

    Florian

    Posted 12 years ago on Thursday February 2, 2012 | Permalink
  2. I was able to add form submissions and turn them into comments by using the following code. In your theme you would have to replace the comment form by adding your gravity form in single.php. There are many posts on here on how to add a form to a template page.

    add_action("gform_after_submission_1", "add_comment"); //change form ID to match your form
    function add_comment($entry, $form){
    
    	$time = current_time('mysql');
    
    	$data = array(
    		'comment_post_ID' => $entry["post_id"] ,
    		'comment_author' => $entry[17], //change to match your author field ID
    		'comment_author_email' => $entry[18], //change to match your email field ID
    		'comment_content' => $entry[32], //change to match your comment field ID
    		'comment_type' => '',
    		'comment_parent' => 0,
    		'user_id' => $entry["created_by"],
    		'comment_author_IP' => $entry["ip"] ,
    		'comment_agent' => '',
    		'comment_date' => $time,
    		'comment_approved' => 1,
    	);
    		wp_insert_comment($data);
    }
    Posted 12 years ago on Thursday February 2, 2012 | Permalink
  3. On one page I basically want to collect some personal info at the same time a comment is generated, was wondering if that was even possible but it looks like it is.

    I'm going to give it a try wih this plus a few more fields that just need to get emailed to someone like a normal form submission.

    Posted 12 years ago on Thursday March 8, 2012 | Permalink
  4. I got this working using the code above with one exception. It doesn't seem to be populating the comment_post_ID field. The comment gets created without being attached to a post and then can't be managed (approve/spam/delete) from the dashboard.

    I ended up hard coding the post ID, since I know the page the form is coming from, not sure why it wasn't working.

    Posted 12 years ago on Friday March 9, 2012 | Permalink
  5. Also just noticed FIELD_ID's should be queried with strings not integers so $entry[17] should be $entry['17']

    Maybe that was the problem with the other stuff too.

    Posted 12 years ago on Friday March 9, 2012 | Permalink
  6. rdpalmer
    Member

    I would also like to get the post_id working. Does anyone have any ideas or another method to get this working?

    Posted 12 years ago on Wednesday September 26, 2012 | Permalink
  7. @rdpalmer, please begin a new topic and clearly state your problem and what you have already tried, and where you are stuck. This topic is over 6 months old and every situation is unique. Thank you.

    Posted 12 years ago on Thursday September 27, 2012 | Permalink

This topic has been resolved and has been closed to new replies.