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.

Can't submit input name array to show up in Entry List

  1. wlcx
    Member

    I'm using the gform_field_input hook to dynamically generate field elements, and that works.

    But I'm generating multiple fields and I need to use a name array (name="foo[]") for my values. So far I'm stuck. I tried "input_$field['id']" which works but as an array, "input_$field['id'][]" does not work.

    I noticed the List fields use name arrays (input_$field['id'][]), so how can I get them to submit and show up in the entry list?

    Any help appreciated. Thanks.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  2. wlcx
    Member

    I figured it out.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  3. Can you share your solution here for the benefit of someone else who might be stuck on the same problem? Thank you.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  4. wlcx
    Member

    Let's say I have
    <input type="number" name="input_2[]" />

    I would use the gform_pre_submission hook to convert the input array to a json string

    add_action("gform_pre_submission_1", "pre_submission_handler");
    function pre_submission_handler($form){
       $_POST["input_2"] = json_encode($_POST["input_2"]);
    }

    Then if I want to render the json string as a list on the Entry detail page I would use the gform_entry_field_value hook like so

    add_filter("gform_entry_field_value", "category_names", 10, 4);
    function category_names($value, $field, $lead, $form){
    
    	if($form['id'] != 1 || $field['id'] != 2)
    		return $value;
    
    	$newvalue = '';
        $choices = json_decode($value, true);
    
        foreach($choices as $choice) {
            $new_value .= '<li>'.$choice.'</li>';
        }
    
        return '<ul>' . $new_value . '</ul>';
    }

    The only issue I have now is that the email notification returns the json string. Is there anyway to format the values before the email notification is sent?

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  5. I would assign your JSON string to another form field and mark that admin only, then allow the email notification to send the original input_2, with your json string stored in another field for your purposes. I would not modify the original input_2.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  6. I'm trying to do exactly the same thing but getting "null" value in return. My input fields look like:

    <input name="field_4[]" type="text" value="Add note...">

    and I'm otherwise basically using wlcx code, just replacing 2 with 4. My full code is at the pastebin link below:

    http://pastebin.com/xRDNmGk3

    The field I'm editing is a a Single Line Text with ID of 4. Any help would be super appreciated.

    Posted 11 years ago on Saturday February 2, 2013 | Permalink
  7. Can you show us where you are using this code? And what is coming up with NULL values?

    Posted 11 years ago on Saturday February 2, 2013 | Permalink
  8. Thanks Chris, the code is in functions.php, and "null" shows up in the Entries page, under the column heading "Shopping List", which is the input I am modifying (ID#4, CSS .subsection). On the front-end, my complete HTML looks like this:

    <li id="field_1_4" class="gfield    subsection">
    
    <label class="gfield_label" for="input_1_4">Shopping List</label><br>
    
    <label for="fav5454">CTC Analytics / Leap Technologies CombiPAL Headspace Autosampler</label><input style="width: 98%" name="field_4[]" id="fav5454" type="text" value="Add question..."><br>
    
    <label for="fav5370">CTC Analytics / Leap Technologies Combi PAL Autosampler for Liquid and Headspace Injections</label><input style="width: 98%" name="field_4[]" id="fav5370" type="text" value="Add question..."><br>
    
    </li>

    Anything glaringly wrong? Thanks in advance.

    Posted 11 years ago on Saturday February 2, 2013 | Permalink