Warning: Undefined variable $post in /home/weformspro/public_html/wp-content/themes/t16-child/wedocs/docs-sidebar.php on line 6

Warning: Attempt to read property "post_parent" on null in /home/weformspro/public_html/wp-content/themes/t16-child/wedocs/docs-sidebar.php on line 6

Warning: Undefined variable $post in /home/weformspro/public_html/wp-content/themes/t16-child/wedocs/docs-sidebar.php on line 11

Warning: Attempt to read property "ID" on null in /home/weformspro/public_html/wp-content/themes/t16-child/wedocs/docs-sidebar.php on line 11

How to Use Dynamic Value Population on weForms

  1. Home
  2. Docs
  3. Tutorials
  4. How to Use Dynamic Value Population on weForms

How to Use Dynamic Value Population on weForms

To be able to dynamically populate your field value, adds a certain amount of user-friendliness in your contact form. The option Dynamic Value Population for weForms allows you to do this.

In order to enable the dynamic field population option, at first, navigate through WP-admin→weForms→All Forms→Add Forms→Blank Form or choose from a Template then follow the below steps.

After enabling the dynamic population value, we have input the Parameter name ‘new_param’ to it. You can also choose your own parameter name in the field here. This particular field now can be dynamically populated using the shortcode inputting your chosen parameter name and value on the edit page as it can be seen below.

Passing Data

Just for your info, you can populate the data dynamically in two ways – Query String and Filter Hooks. Before doing that, you will need to specify a parameter name of your choice that will be used to pass the value just like above. Here is an example of passing the data in both the cases.

Passing Data Using Query String

You can pre-populate a field via the query string by appending the dynamic population parameter you specified for the field to the end of your form URL along with your custom value.

Just simply input your form URL along with your site URL adding your chosen parameter name and its value. For Example http://siteurl.com/form-url/?your_parameter=value. For demonstration purpose, we have chosen the parameter name as ‘new_param’ and set the value to ‘abc@email.com’. You can see the full demonstration of this query string data passing below:

Passing Data Using Hooks

You can also populate a field using hooks. For that, you will need to enable the dynamic value population option and set a parameter.  Here is an example of that –

// populating options for PARAM_NAME
add_filter( 'weforms_field_options_PARAM_NAME', 'populate_countries_to_weforms', 10, 2 );

function populate_countries_to_weforms( $options , $form_id ){

// these data can come from the database or some other place 
$country_array = array(
"AU" => "Australia",
"BD" => "Bangladesh",
"BR" => "Brazil",
"CN" => "China",
"GB" => "United Kingdom",
"US" => "United States", //add more countries if you want
);

return $country_array;
}

Here, we have used the Parameter Name to ‘PARAM_NAME’.

After adding the code, this is how the code looks like.

If you have any further queries then contact our support team

Was this article helpful to you? No 1 Yes 1

How can we help?