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.

Switching forms based on field selection by user

  1. FanaticWeb
    Member

    I looked around for this type of thread and I have not found anything similar, apologies in advance if this ends up being a duplicate thread, please feel free to move it around if need be.

    Similar thread (http://www.gravityhelp.com/forums/topic/conditional-elements-based-on-url-or-multiple-forms-posting-to-single-database)

    Switching/Jumping to different forms based on user selection (drop down field, checkbox or Radio button), is it possible?

    Example: I currently have 1 form which requires the user to choose whether they are Local residents or Tourists (Radio button), if they identify themselves as Locals, then they will have the dedicated "Local" fields to fill out, if they are Tourists, then different fields are displayed, so far so good since I can use the Conditional logic to Hide or Show those fields based on the initial user selection, BUT, my problem is the Content template, the output on the front end once the form is submitted :(

    No matter what I thought of so far, I'm stuck pushing all the fields within the content template which holds the entry fields of both Locals and Tourists, yet I would like the form to only push the fields based on the user type selection to avoid mixing the content fields or ending up with blank entries since not all fields are common to both users.

    Simplified workaround: (Create 2 different pages and deploy seperate forms for each type of user)

    As an alternative, what I thought of doing is to create a page where the user simply selects if they are Local or Tourists and then jump to a different page that has the appropriate form based on the user's selection (a simplified 2 steps process) thereafter the content template will only pull and output the corresponding fields based on that particular form.

    I would really like to avoid this duplicate task and I'm wondering if we can achieve it within one single form?
    Bottom line, its all about including and outputting the appropriate fields within the Content Template (ex.: if User type = Local (Hide field x,y,z + Output field A,B,C). If User type: Tourist: (Show field x,y,z + Hide field A,B,C)

    If you got a headache reading this thread, coffee is on me :) *limited to GF staff cause I'm not rich* !! lol

    Posted 12 years ago on Tuesday January 17, 2012 | Permalink
  2. Hi, FanaticWeb,

    I apologize for the delayed response to your post.

    Since you are using post content templates to format the display, you could create the post content template manually using the hook "gform_pre_submission_filter". This way you can create the content template based on the radio button selection and only include the fields you need for the selection. Below is an example:

    //add filter for form id 23
    add_filter("gform_pre_submission_filter_23", "pre_submission_filter");
    function pre_submission_filter($form)
    {
    	//check value of radio button and build content template
    	if (rgpost("input_8") == "Local")
    	{
    		//put fields used for local into postContentTemplate, use "\n" for a carriage return
    		//use merge tags, easiest to build the template in the admin and copy out what you need for the fields
    		$form["postContentTemplate"] = "This is my template when the user is a Local\nTitle: {Local Field 1:10}";
    	}
    	else
    	{
    		//put fields used for tourist into postContentTemplate
    		$form["postContentTemplate"] = "This is my template when the user is a Tourist\nTitle: {Tourist Field 1:9}";
    	}
    	//return modified form object, the merge tags will be replaced after this
    	return $form;
    }

    Take a look at this and let me know if you have any questions.

    Posted 12 years ago on Wednesday February 1, 2012 | Permalink
  3. FanaticWeb
    Member

    Ahh! I had applied the 3 different forms but I'm definitely gonna boomark this thread and give the suggested code a shot, thank you Dana.

    Posted 12 years ago on Thursday February 2, 2012 | Permalink

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