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.

Can I specify Default Choice in Shortcode

  1. mattswan
    Member

    I have a single form that is used on many pages across a site.

    The form contains a drop down field with around 50 options in it (it's a listing of towns and cities where we have hotels) and I'd like to ask if it might be possible to specify which of those options displays by default on each page by editing the shortcode that calls the form?

    I'd rather not have to make 50 forms, each with the correct location defined as the default choice.

    Any help much appreciated.
    m@

    Posted 12 years ago on Monday August 22, 2011 | Permalink
  2. This is a really good question.

    Doing it all with one form is definitely the way to do it. You're OK with editing the shortcode in each of 50 pages to set the default for that particular page?

    Did you insert the shortcode into each page already, or can you insert the form into each page in the template using the function call?

    Are there any custom fields or anything else to work with, where we would know which select value to have selected as default, based on that page it's embedded in? I'm thinking of a custom field like "hotelcity" or something, and then the value is "Chicago". Based on that, we set the "selected" value in the select box as "Chicago".

    I think it would be easier to do this programatically than manually by editing the shortcode for each page, which is why I asked about the custom fields.

    Posted 12 years ago on Monday August 22, 2011 | Permalink
  3. To answer the initial question though, I don't think you can using the shortcode. It will either be a jQuery solution or use a hook to change the "selected" value before the form is displayed.

    http://www.gravityhelp.com/documentation/page/Field_Object

    Posted 12 years ago on Monday August 22, 2011 | Permalink
  4. I have this worked out using the gform_pre_render hook. We need a way to match the page the form is displayed on to the default "selected" value. It could even be a custom field key and value, where the value is the select item to be the default. If you're not already using a custom field that could be utilized for this purpose, it could be a key of "defaultselect" (or whatever you want it to be) and then a value that is the number in the select list that should be selected. Each page would have to have this custom field key and value.

    If you go that route, the array is zero based, so the first select item is 0, second one is 1, etc. For 50 hotels, you'd have values from 0 to 49. For example, with states alphabetical:

    [0] Alabama
    [1] Alaska
    [2] Arizona
    [3] Arkansas
    [4] California
    [5] Colorado
    [6] Connecticut
    [7] Delaware

    Posted 12 years ago on Monday August 22, 2011 | Permalink