Dynamic default value

Dynamic default value

Email Address → Settings → Optional

Allows the default value of the field to be set dynamically via a URL parameter, shortcode attribute, PHP function parameter or filter hook.

URL parameter

You can pass in parameters to the URL to set the default value of fields. Once you’ve set the Parameter name, use the code below to do this. In the following examples, I have set the Parameter name to my_parameter, so you’ll need to change this to the value of your own parameter name.

http://example.com/?my_parameter=Banana

Your element will now have the value Banana when the form is displayed. Note: if your URL already has a question mark (?) in it, you should use an ampersand (&) to add further parameters e.g.

http://example.com/?p=1&my_parameter=Banana&my_parameter2=Apple

Shortcode attribute

You can use a shortcode attribute called values to pass parameters to the forms. Using the same rules for each element as specified above, only this time each parameter should be separated by &

[iphorm id=1 name="Contact form" values="my_parameter=Banana&my_parameter2=Apple"]
[iphorm_popup id=1 name="Contact form" values="my_parameter=Banana&my_parameter2=Apple"]Click me[/iphorm_popup]

Filter hook

You can use a filter hook in a plugin or your theme PHP files to change the value. This will take precedence over the other methods. The parameter $value passed to the function is any previous default value set from the URL or shortcode. Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
3
4
5
6
add_filter('iphorm_element_value_my_parameter', 'my_set_parameter');
 
function my_set_parameter($value)
{
    return 'New value';
}
add_filter('iphorm_element_value_my_parameter', 'my_set_parameter');

function my_set_parameter($value)
{
	return 'New value';
}

PHP function parameter

You can pass in dynamic values to the function call to iphorm and iphorm_popup functions. When using the iphorm function, it’s the second parameter (after your form ID). For the iphorm_popup function, it’s the fourth parameter. The values can be passed in as a string with each key/value pair separated by & or & or you can also pass in an array of key => value pairs. The key will be your parameter name. For example:

Display the form with values in the given string

1
<?php if (function_exists('iphorm')) echo iphorm(1, 'my_parameter=Banana&amp;my_parameter2=Apple'); ?>
<?php if (function_exists('iphorm')) echo iphorm(1, 'my_parameter=Banana&amp;my_parameter2=Apple'); ?>

Display the form with values in the given array

1
2
3
4
<?php if (function_exists('iphorm')) echo iphorm(1, array(
    'my_parameter' => 'Banana',
    'my_parameter2' => 'Apple'
)); ?>
<?php if (function_exists('iphorm')) echo iphorm(1, array(
    'my_parameter' => 'Banana',
    'my_parameter2' => 'Apple'
)); ?>

Display the popup form with values in the given string

1
<?php if (function_exists('iphorm_popup')) echo iphorm_popup(1, 'Click here to show the form', '', 'my_parameter=Banana&amp;my_parameter2=Apple'); ?>
<?php if (function_exists('iphorm_popup')) echo iphorm_popup(1, 'Click here to show the form', '', 'my_parameter=Banana&amp;my_parameter2=Apple'); ?>

Display the form with values in the given array

1
2
3
4
<?php if (function_exists('iphorm_popup')) echo iphorm_popup(1, 'Click here to show the form', '', array(
    'my_parameter' => 'Banana',
    'my_parameter2' => 'Apple'
)); ?>
<?php if (function_exists('iphorm_popup')) echo iphorm_popup(1, 'Click here to show the form', '', array(
    'my_parameter' => 'Banana',
    'my_parameter2' => 'Apple'
)); ?>

Parameter name

Email Address → Settings → Optional

Set the name of the parameter to use as the default value.

Still having trouble? Head over to the forums.

Forums