awsmug / torro-forms

Torro Forms is an extendable WordPress form builder with Drag & Drop functionality, chart evaluation and more - with WordPress look and feel.
https://torro-forms.com
GNU General Public License v2.0
85 stars 32 forks source link

Feature: Pre select form fields by hook #265

Closed zottto closed 8 years ago

zottto commented 8 years ago

It would be nice to have a hook when loading the form in the frontend to prefill fields or pre-select values (e.g. based on some URL parameters).

tyrann0us commented 8 years ago

Similar to how Contact Form 7 does this: http://contactform7.com/getting-default-values-from-the-context/

mahype commented 8 years ago

I have added the possibility to add preselected values by $_GET param.

  1. Check the settings in form "Allow $_GET parmeters"
  2. Add your content by adding param to form URL with "FORMURL?torro_input_value_ELEMENT_ID=VALUE"

You also cen preset the value by filtering 'torro_input_value' filter.

Filter: apply_filters( 'torro_input_value', $value, $element->id );

zottto commented 8 years ago

Hi @mahype,

I tried that with a checkbox. The URL looks like: http://my-site/kontakt/?torro_input_value_torro_form_element_5-1=true

I also tried "1" and "checked" as value, but the checkbox is not selected.

What am I doing wrong?

Thanks, Marc

tyrann0us commented 8 years ago

@zottto: Preselecting a checkbox or radio buton requires the attribute checked="checked" to be set, 5f92b63d40e6b7a964ea3709422d7f3c739c4354 only changes the value attribute. So you'll have to wait for @mahype to extend this feature.

mahype commented 8 years ago

As discussed on Skype, now you can select the element value by the answer ID if you have preselected answers in case there is a complex text string.

This is already possible. Here is the list of all elements:

Textfield, Textarea ?torro_input_value_ELEMENTID=ANSWER_ID1

Onechoice, Dropdown ?torro_input_value_ELEMENTID=ANSWER_ID1

Multiple Choice for one value ?torro_input_value_ELEMENTID[]=ANSWER_ID1

Multiple Choice for multiple values ?torro_input_value_ELEMENTID[]=ANSWER_ID1&torro_input_value_ELEMENTID[]=ANSWER_ID2

Pleas get your element and answer IDs from the admin sourcecode.