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.

Same Field Twice on Same Form

  1. I have a muli-page form and I would like to carry the value from text field A on step 1 to text field B on step 3.

    Preferably, I would like to only have one database entry for these fields, rather than having two ids and dynamically populating the field B with the value from A.

    Which is the best way to handle this?

    Posted 11 years ago on Tuesday June 25, 2013 | Permalink
  2. If I am understanding you correctly, you basically want a dummy field that will accept the data from a user and use that data to populate a real field on another page. You do NOT want the data from the fake field to be a part of the entry, only the field that was populated with data from the "fake" field. If my understanding is correct, you could do something like the example below. In this example, I use the gform_pre_render hook to add the fake field to the form object so that when the form is displayed the fake field shows. The data that is POSTed for the fake field will be available on subsequent pages for use. It is then used to populate a field on the third page using its value from the $_POST object. Take a look and see if this gets you what you need. You will need to change the form id and field ids as mentioned in the comments.

    //target form id 218
    add_action("gform_pre_render_218", "create_dummy_field");
    function create_dummy_field($form){
    	$current_page = GFFormDisplay::get_current_page($form["id"]);
    	//create dummy form field in form object, the data will be in $_POST for use on another page
    	//the id of 6 in this example was chosen because the last field id in use on my form is 5, make sure the id is NOT already in use on your form when you create the fake field
    	//change the formId, label, and if the field is required set it to true, change the pageNumber if necessary, the type of text is a single line text field
    	$new_field = array("0" => array("formId" => 218, "id" => 6, "label" => 'Fake Field', "isRequired" => false, "pageNumber" => 1, "type" => "text"));
    	$fields = $form["fields"]; //get existing form fields
    	//merge new field with existing fields so fake field is in form object
    	$form["fields"] = array_merge($new_field, $fields);
    
    	if ($current_page == 3){
    		//get data from fake field and put into field that will be saved with the entry
    		foreach ($form["fields"] as &$field){
    			if ($field["id"] == 5){
    				//populate with post data from fake field
    				$field["defaultValue"] = $_POST["input_6"];
    			}
    		}
    
    	}
    	return $form;
    }
    Posted 11 years ago on Monday July 1, 2013 | Permalink

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