Title: Populate field from shortcode parameter
Last modified: October 7, 2021

---

# Populate field from shortcode parameter

 *  Resolved [nikonikoneko](https://wordpress.org/support/users/nikonikoneko/)
 * (@nikonikoneko)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/)
 * Hi,
 * I would like to populate a (hidden) field from a shortcode parameter, e.g. like
   this: `[forminator_form id="421" my_field="5"]`. Is that possible? We have a 
   child theme, so adding a filter or something like this would be easy enough.
 * Background is that we want to reuse a form for subsequent events, so it would
   be convenient if we didn’t have to edit/copy the form for every event.
 * Thanks in advance!
    Nikolas

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [Imran – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support9/)
 * (@wpmudev-support9)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/#post-14952092)
 * Hello [@nikonikoneko](https://wordpress.org/support/users/nikonikoneko/) !
 * I hope you’re doing well.
 * You can use the snippet below to achieve a similar result:
 *     ```
       add_filter( 'forminator_cform_render_fields', function( $wrappers, $form_id ){
       	$your_form_id = 123;
       	if( $form_id == $your_form_id ){
       		$_REQUEST[ 'query-var-hidden-1' ] = 'test1';
       		$_REQUEST[ 'query-var-hidden-2' ] = 'test2';
       	}
       	return $wrappers;
       }, 10, 2 );
       ```
   
 * To configure it, please do the following:
    – change the $your_form_id to match
   the ID of your form (you can find the ID in the shortcode) – then you can set
   query variables – the “query-var-hidden-1” can be anything else, but please don’t
   use spaces there and the ‘test1’ is the value, so in your example it will be:
 *     ```
       add_filter( 'forminator_cform_render_fields', function( $wrappers, $form_id ){
       	$your_form_id = 421;
       	if( $form_id == $your_form_id ){
       		$_REQUEST[ 'my_field' ] = '5';
       	}
       	return $wrappers;
       }, 10, 2 );
       ```
   
 * You can set as many of the REQUEST variables as you like.
 * Next step would be to edit the field that should be filled in and the Settings
   tab fill in the query variable that will be used to populate the field:
 * > [View post on imgur.com](https://imgur.com/a/706O9ft)
 * And that’s it 🙂
 * Hope this helps!
 * Kind regards,
    Pawel
 *  Thread Starter [nikonikoneko](https://wordpress.org/support/users/nikonikoneko/)
 * (@nikonikoneko)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/#post-14954554)
 * Hey Pawel,
 * hope you’re doing well and thank you for your reply!
 * Unfortunately this is not what I need :/ I actually wanted adjust default values
   from the **shortcode** of a form without having to edit it, i.e. all from within
   a post.
 * I tried adding a new shortcode using your $_REQUEST tinkering. The form shows
   up, but no luck with the query parameter yet :/
 *     ```
       add_shortcode('forminator_form_ext', 'do_forminator_form_ext');
       function do_forminator_form_ext( $atts ) {
       	$the_id = $atts['id'];
       	unset($atts['id']);
   
       	add_filter('forminator_cform_render_fields', function( $wrappers, $form_id ) use ($the_id, $atts) {
       		if ( $form_id == $the_id ) {
       			foreach( $atts as $a ) {
       				$_REQUEST[$a] = $atts[$a];
       			}
       		}
       		return $wrappers;
       	}, 10, 2);
   
       	return do_shortcode('[forminator_form id="' . $the_id . '"]');
       }
       ```
   
 * If you happen to have any suggestions it would be greatly appreciated!
 * Best regards,
    Nikolas
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/#post-14955985)
 * Hi [@nikonikoneko](https://wordpress.org/support/users/nikonikoneko/)
 * I found this old script created by our developers that may help you.
 *     ```
       add_shortcode( 'wpmudev_forminator_form', function( $atts = array() ){
       	$atts = shortcode_atts( array(
       		'id' => null,
       		'field_values' => ''//"parameter_name1=value1&parameter_name2=value2"
       	), $atts );
       	if( ! empty( $atts['field_values'] ) ){
       		$atts['field_values'] = htmlspecialchars_decode( $atts['field_values'] );
       		$params = explode( '&', $atts['field_values'] );
   
       		foreach( $params as $param ){
       			list( $key, $value ) = explode( '=', $param );
       			$_REQUEST[ $key ] = $value;
       		}
       	}
       	return do_shortcode( sprintf('[forminator_form id="%d"]', $atts['id'] ) );
       } );
       ```
   
 * But this only works if the Forminator > Form > Behaviour > Load form using AJAX
   is disabled.
 * Let us know if this code helped you.
    Best Regards Patrick Freitas
 *  Thread Starter [nikonikoneko](https://wordpress.org/support/users/nikonikoneko/)
 * (@nikonikoneko)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/#post-14959956)
 * Ahhhhh, it works 😌 Thank you so much! This was extremely helpful 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Populate field from shortcode parameter’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 4 replies
 * 3 participants
 * Last reply from: [nikonikoneko](https://wordpress.org/support/users/nikonikoneko/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/populate-field-from-shortcode-parameter/#post-14959956)
 * Status: resolved