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.

Trying dynamic checkboxes population

  1. Hi. I have this code for population a group of checkboxes:

    add_filter("gform_pre_render_7", "pre_survey");
    function pre_survey($form){
       global $wpdb;
    
       $strSQL = 'SELECT name FROM wp_pod_tbl_treatment1 ORDER BY name';
       $tmts = $wpdb->get_results($strSQL);
       $i = 0;
       foreach($tmts as $tmt) {
             $i1 = $i+1;
             $id = '10.' . $i1;
             $form['fields'][5]['choices'][$i]['text'] = $tmt->name;
             $form['fields'][5]['choices'][$i]['value'] = $id;
             $form['fields'][5]['choices'][$i]['isSelected'] = ($_POST['input_10_' . $i1]);
             $form['fields'][5]['inputs'][$i]['id'] = $id;
             $form['fields'][5]['inputs'][$i]['label'] = $tmt->name;
             $form['fields'][5]['inputs'][$i]['name'] = $id;
             $i++;
       }
       return $form;
    }

    The problem is some checkboxes seems not to be stored or even kept when I go to next page and then go back to this page. Am I doing something wrong ?

    Also, I would like on next page to show a question for every marked checkbox. Is this the correct hook where I can do this ? Is there any example in how to achieving this ?

    Thanks.

    Posted 12 years ago on Monday September 17, 2012 | Permalink
  2. Please see this reply by lead developer Alex Cancado:
    http://www.gravityhelp.com/forums/topic/dynamic-checkboxes#post-9476

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  3. Thanks for your answer. Yes, I had already seen this. In fact I think my code is very similar, but I think there is something wrong because some checkboxes are kept and some others doesnt.

    Please try this page: http://absoluteme.co.uk/survey/

    and then try to mark checkboxes on the right column from "Sculptra" to "Thermage" (you should be registered to make this, but it's free). Then press "Next" and then press "Previous" to return to the same page and see which checkbox values are retained and which aren't retained (since "Slim Lipo" are not retained). Maybe there is a maximum checkboxes limit on a group since then values are not retained ?

    Thanks.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  4. When you say kept, do you mean the checkbox status is not kept? Or the checkbox itself is not there? I think we are talking about two different things.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink