WordPress.org

Ready to get started?Download WordPress

Forums

Ninja Forms
Populate textarea from querystring (3 posts)

  1. ChrisGoodwinNH
    Member
    Posted 4 months ago #

    Do you have an extension that would allow is to pre-fill a textarea box with different values based on a querystring value?

    For example, http://www.example.com?prod=X22A would result in the textarea being pre-populated with "Reference to product X22A".

    Thank you. I really like the Ninja Forms plug-in.

    https://wordpress.org/plugins/ninja-forms/

  2. James Laws
    The WP Ninjas
    Plugin Author

    Posted 4 months ago #

    We try to assist everyone who asks for support butss we’ve stated in this sticky thread, we don’t offer support on these forums. This is to help us provide support more efficiently by keeping it all in one channel.

    If you would like support from the developers you can follow the support link it provides and we’d be happy to assist you.

    If you are happy waiting here to see if someone else can assist you you are welcome to do that as well.

  3. C_E_C
    Member
    Posted 3 months ago #

    Here's how I solved it, your mileage may vary. Note that all of the php listed should go in your template's functions.php file.

    Step 1) Tell WordPress about any custom query string parameters you're looking for. Source

    <?php
    function add_query_vars_filter( $vars ){
      $vars[] = "my_query_string_parameter";
      return $vars;
    }
    add_filter( 'query_vars', 'add_query_vars_filter' );
    ?>

    Step 2) Add an action to the ninja_forms_display_init hook that will run as the form is loaded. Then use get_query_var to get the query string value you're looking for. Finally, pass that value the Ninja Forms api method update_field_value using the ninja_forms_loading global object.

    <?php
    function handle_http_query_string( $form_id ){
    	global $ninja_forms_loading;
    	$ninja_forms_loading->update_field_value( my_field_id, get_query_var('my_query_string_parameter'));
    }
    
    add_action( 'ninja_forms_display_init', 'handle_http_query_string' );
    ?>

Reply

You must log in to post.

About this Plugin

About this Topic