Tip: setting optional form parameters with shortcode

Posted by on Feb 7, 2011 in How To, Tips

Tip: setting optional form parameters with shortcode. This can be useful in special situations where you need to set settings in a different way.

These are WordPress version only features:

Note: with the plugin versions 4.x and higher, you have to enable the setting “Enable PHP sessions” or this feature is ignored. If you enable this setting, test your form and site to be sure it supports PHP sessions. PHP Sessions are no longer enabled by default allowing for best compatibility with servers, caching, themes, and other plugins. This should resolve many sessions related issues some users had.

Setting optional redirect with shortcode:
A user wanted to be able to optionally use shortcode to add a redirect that overrides the one in settings.
Example:
[si-contact-form form=’1′ redirect=’http://www.mysite.com/thanks’]

“It would be very useful to be able to set some form fields or options via the WP shortcode. In my case I have different pages that uses the same form and that just have to redirect to different pages. So it would be perfect to set the redirect target for each page via a shortcode by still using the same form…
(I think in other situations it’s interesting to be able to set at least some hidden fields.)”

Setting optional extra hidden fields with shortcode:
Optional list of key value pairs that need to be added. Type the key separated by the equals character, then type the value, like this: key=value
If you need multiple pairs, start each new entry after a comma.
The extra fields will be included in the email and exported data.

Examples:
[si-contact-form form=’1′ hidden=’account=3629675′]
[si-contact-form form=’1′ hidden=’account=3629675,newsletter=join’]

Setting to show Form Page URL in the email
(not available in version 3.1.4.1 or older)
[si-contact-form form=’1′ hidden=’form_page=1′]

Setting optional email_to with shortcode:
Each contact has a name and an email address separated by a comma.
Webmaster,user1@example.com (must use this format: name,email)
Also, you can have multiple E-mails, this is called a CC(Carbon Copy). Separate each CC with a semicolon.
Webmaster,user1@example.com;user2@example.com (must use this format: name,email;email;email)
Note: this will override any email_to that is set in the form settings!

Examples:
[si-contact-form form=’1′ email_to=’Webmaster,user1@example.com’]
[si-contact-form form=’1′ email_to=’Webmaster,user1@example.com;user2@example.com’]

Setting with PHP in a template rather than shortcode:
There may be situations where you need to dynamically set special parameters using PHP in your page template. You can use this PHP code instead of the shortcode.

<?php
if ( isset($si_contact_form) )  {
 echo $si_contact_form->si_contact_form_short_code( array(
 'form' => '1',
 'email_to' => "$name,$email_to",
  ) );
}
?>

If you use any of these feature, please contact me and tell me if they were useful or not, thanks – Mike Challis

Do you need help?

Send us a Donation:

Donate to Mike Challis