ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Select drop down based on link clicked

March 04, 2011 8:50pm

Subscribe [2]
  • #1 / Mar 04, 2011 8:50pm

    Charming Nerd

    196 posts

    I am converting a site to EE that has a enrollment form. On this form there is drop downs for a user to select a trip type. On trip pages there are links that bring the user to this page and automatically select the appropriate trip from the drop down. The site is done in coldfusion and it is accomplishing this by passing the ID in the URL. Something like this:

    /reservations/step1.cfm?TripID=33


    So, how can I replicate this in EE? I would likely be using Freeform. I would also like to use friendly urls if possible. So, I am thinking there might be a way to do it with segments?

  • #2 / Mar 04, 2011 9:18pm

    John St-Amand

    865 posts

    Yes, you could accomplish it by adding a conditional based on segment in each option in the select box.  Just come up with your own set of id’s and pass them into the URL. Then in the option tags just conditionally add “selected” to the option that matches the last segment. Make sense?

    Hope that helps!

  • #3 / Mar 04, 2011 9:22pm

    Charming Nerd

    196 posts

    Thanks for the reply. I forgot to add an important part to the question. The drop down has to be created dynamically based on what trips are available at the time. So yeah, that makes it a bit more complicated i presume.

  • #4 / Mar 04, 2011 9:47pm

    John St-Amand

    865 posts

    Thanks for the reply. I forgot to add an important part to the question. The drop down has to be created dynamically based on what trips are available at the time. So yeah, that makes it a bit more complicated i presume.

    Not necessarily all that bad, no. You could instead pass the ID of the trip entry into the URL. Then in the form, you can dynamically generate the select box’s options using an entries loop of the available trips as well.  Then, the same conditional described applies - if the ID in the option matches the ID in the segment, you add selected to the option.

  • #5 / Mar 04, 2011 9:50pm

    John St-Amand

    865 posts

    Oh, there used to be the odd hiccup when using an entries loop to generate the options of the select box when using Freeform - not sure if it’s been resolved. The way around it at the time was to put the select box in an embedded template so that the options were parser before the rest of the form template. Just thought I’d alert you to that ahead of time. But as I mentioned, that may be a resolved bug by now.

  • #6 / Mar 04, 2011 10:04pm

    Charming Nerd

    196 posts

    Thanks for the help. I can not wrap my head around what the actual code would be right now because I have only done one EE site, but it’s good enough for now to know that it can be done so I can make my proposal.

  • #7 / Mar 05, 2011 10:04am

    John St-Amand

    865 posts

    No problem. Rest assured, it’s accomplished easily enough, probably in more than one way, with EE. Good luck!

  • #8 / Mar 05, 2011 3:43pm

    Charming Nerd

    196 posts

    When the time comes, maybe I will hit up this thread if I am having trouble.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases