Prepopulate form fields with default values
Visforms enables you to set default values for field types that allows free user inputs. Default values are values, which are already entered when a user opens a form. Usually a user can change the default values if needs be. Unchanged default values are submitted with the form in the same way as any user input.
Visforms offers you two different approaches to set a default value for a field. You can either set a default value in the field configuration or you can prepopulate a field through url parameters. Default values, set in the field configuration can either be a fixed value or they can be gathered from the user profile ot the currently logged on user (i.e. the e-mail address of the currently logged on user, whereas using url parameters allows you to set a default value dynamically during the run time.
This article explains how you can set default values for different field types in the field configuration.
Field type: Hidden
Hidden fields are invisible for the user. Therefore a user cannot make any inputs. You can use hidden fields to submit additional information of your choise with the form. This information is passed by a default value.
You can either pass a static text with a hidden field. Please enter the text in the "Value" option of the hidden field. Alternatively you can check the "Add unique id to value" checkbox. Visforms will automatically create a unique id (hash) and add it to the default value of the hidden field each time the form is submitted.
Field type: Text
You can use any custom text as default value for fields of type text. Just enter the text in the "Initial Value" option of the form field and set the "Fill field with" option to "Initial Value".
Alternatively you can use user profile information of the logged in user as default values in text fields. You can choose between the following user data (Select form the "Fill field with" listbox).
- Name
- User name
- Address 1
- Address 2
- City
- State
- County
- Zip Code
- Phone
If a user is not logged in, text fields with defaults values different from the "Initial Value" remain, of course, empty.
Since version 3.7 Joomla! enables you to create "Custom User Fields". In combination with Joomla! 3.7 or higher, you can use "Custom User Field" values of the logged in user as default values in Visforms. Each custom user field of type text will automatically be displayed in the select list "Fill Field With". This feature is only available with the Visforms Subscription and not part of the free Visforms version..
Field type: emaill
Fields of type email work similar to text fields. (See above). You can select the email address of a connected user as default value.
Field type: Date
For fields of type date you can either set a fixed date as default value (select in option "Initial value") or you can check the checkbox "Day date" in order to always use the current date als default value of the date field. Please notice, that you have to leave the "Initial value" option empty, if you want to use the "Day date" option.
The Visforms Subscription allows you further on, to set a default date value relative to the current date (for example shifted 3 days into the future or 4 days into the past).
Field types: Number, Password, Url, Textarea
You can add a custom text as default value to this field types. Enter this text in the "Initial value" option.
Field types: Checkbox, Checkbox Group, Radio Button and Select
Checkboxes, checkbox groups, radio buttons and selects are field types, where a user always has to select from a list of predifined options. You can preselect an option (set it as default) from the option list of checkbox groups, radio buttons and selects (see Create a radio button, a select list or a checkbox group in Visforms. For fields of type checkbox, you can use the field option "Checked" in order to deliver the checkbox in a check state.