WordPress.org

Ready to get started?Download WordPress

Forums

Auto-fill/Pre-fill depending on post (5 posts)

  1. johso
    Member
    Posted 3 years ago #

    Hi guys,

    I am creating a website where people can apply for an item.
    I would like to set up a form that automatically gets the details of the post, so it would look something like this:

    -----
    Apply for item
    Name: <pre-filled if registered>
    Email: <pre-filled if registered>
    Subject: <pre-filled with the name of the post>
    Item: <drop-down box with options of items that were available in post>
    Comment: <free for user to fill in or not>
    ---

    - So the idea is that the form snippet is the same and it's attached to every post, but fills the forms depending on what information is in the post.

    I've been looking at Contact Form 7 and SI Contact, but none of them do this, at least not out of the box.

    Could anyone be so kind as to put me in the right direction?

    Thank you in advance, any help is appreciated.

  2. MichaelH
    Member
    Posted 3 years ago #

    This is a pretty robust plugin:
    http://www.deliciousdays.com/cforms-plugin/

  3. Girmay
    Member
    Posted 3 years ago #

    This is about month late but you are in luck my friend. I did modify cf7 to do just that.
    Takes "post title" puts it in a dropdown where a user can select one.
    check out http://babakahn.com/2010/limo/
    The "What EVENT are you attending?" is pulled from a post title.
    I only need it to do dropdown but I am sure you can make it work for textboxes and such.

    The file you will need to modify is select.php and it is under the "modules" folder with in cf7.
    Open up select.php and on line 93 (right under $label = $value;)
    paste the following code.

    if ($name == 'events') {
    
     $cf7_dropdown = new WP_Query("cat=1");
     while($cf7_dropdown->have_posts()) : $cf7_dropdown->the_post();  
    
    	  if ( !in_array( get_the_title(), $do_not_duplicate ) ) {
    		 $do_not_duplicate[] = array_unique($do_not_duplicate);
    	 	 $html .= '<option value="' . esc_attr(get_the_title()) . '"' . '>' . esc_html(get_the_title()) . '</option>';
    		  array_push($do_not_duplicate, get_the_title());
    
    		}
    
    				endwhile;
        } else {

    Create a contact form that includes your dropdown (notice the $name = 'events' on top?..that is the name of my select field within my contact form)
    [select events]
    it doesn't event matter what value you give it
    [select events "this value doesn't matter" "neither does this one"]
    all that value will be ignored.

    Don not forget to change the cat ID.
    new WP_Query("cat=1");
    you can also pull from multiple cat
    new WP_Query("cat=1,3,4,2");

  4. johso
    Member
    Posted 3 years ago #

    Thanks for posting this girmay!

  5. sandwichnyc
    Member
    Posted 3 years ago #

    I've tried Girmay's solution above and the select I used does populate with the post titles I want to use. However, on submission of the form, the email doesn't populate with the value selected and it also does not populate any selections from the group of checkboxes that is in the form. Regular text field values and file upload do work. Does anyone know how to fix this?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.