PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Multiple copies of same form on one page with dynamic population?

  1. I am trying to display a form associated to each row inside a table of CPT output (think archive-.php level view.

    $field_values = 'comment_mode=email&comment_receiver=' . $emailAddress;
    
    $output .= do_shortcode('[gravityform id="' . COMMENTFORM_ID . '" title="false" description="false" ajax="true" field_values="' . $field_values . '"]');

    That code will work the first time the shortcode is presented on screen, but not all. I am trying to include it as a part of a heavily customized WP_Query loop within a shortcode for a plugin where it could be repeated 20 - 30 times per page - css / js will show/hide the actual form when the user clicks that they would like to comment on the CPT row involved.

    Writing this support post out, it seems like it would be more efficient to have one form and somehow pass the variables which change per row to the form when the user clicks the button that is specific to that row to show / hide the form, but not quite sure how to do that.

    Any suggestions? or examples where others are using a single form multiple times on the same page that could work when being called in the plugin code for generating a shortcode?

    Posted 12 years ago on Sunday February 26, 2012 | Permalink
  2. Amazing what a good night of sleep can do for a complex problem ;)

    You can close this ticket as I solved it this morning with the idea mentioned as potential above.

    For anyone else trying - here are some of the steps / code snippets that will help:

    1. Create your form fields as standard with admin only and include a css class identifier to them.
    2. Within the shortcode output, have a button or onClick item that passes your JS function call and any variables you need populated to the form.
      $output .= '<br/><input type="button" value="Connect!" onclick="rideshare_connect(\'buddypress\', \'' . $username . '\', \'' . $current_user->user_login . '\')" >';
    3. Register the JS script with the function
      add_action("wp_enqueue_scripts", array(&$this, "frontend_scripts_init"));
      function frontend_scripts_init() {
          	wp_register_script('rideshare-connect', IDEALIEN_RIDESHARE_PATH . 'jquery/idealien_rideshare_connect.js', array('jquery') );
      		wp_enqueue_script('rideshare-connect');
      	}
    4. Use the variables and css codes to populate input values as needed.
      function rideshare_connect(mode, receiver, sender) {
      	jQuery(".idealien_rideshareComments_wrapper .gfield input").val("");
      	jQuery(".idealien_rideshareComments_wrapper ul li.connect_mode input").val(mode);
      
      	if(mode == 'buddypress') {
      		jQuery(".idealien_rideshareComments_wrapper ul li.connect_sender input").val(sender);
      	}
      
      }
    5. In my case I then used the gform_after_submission filter to send notifications to buddyPress via its' messages_new_message function and/or emails via WP_mail.
    Posted 12 years ago on Sunday February 26, 2012 | Permalink
  3. Nice, thanks for posting your solution!

    Posted 12 years ago on Sunday February 26, 2012 | Permalink

This topic has been resolved and has been closed to new replies.