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.

Dynamic checkbox population oddity

  1. Hi,

    I've got a form_pre_render() function created which reads a database table to determine whether a checkbox is supposed to be checked or not (this works fine). The form is then supposed to update the table on submit (have a gform_after_submission() function for that).

    Something odd is going on though. Every 10 days (the check boxes are one per day of the month), it seems either my code, php or the gforms code seems to "skip" an id so although the form displays properly (all days are there), the $entry traversal code gets messed up. The "mess-up" increments by 1 every 10 days so:

    <li class='gchoice_2_9'><input name='input_2.9' type='checkbox' value='9' id='choice_2_9' tabindex='10' /><label for='choice_2_9'>Jan 9</label><li class='gchoice_2_11'><input name='input_2.11' type='checkbox' value='10' id='choice_2_11' tabindex='11' /><label for='choice_2_11'>Jan 10</label>

    The same thing happens on the 20th (ID skips 2_21) and the 30th.

    My code for creating the $choices and $inputs (apologies for the cut/paste as well as _ugly_ code:

    [SNIP]
    for ($i = 0; $i < $numDaysInMonth ; $i++)
    {
    $cnt = $i + 1;

    $sqlStr = "SELECT boolDay" . $cnt . " FROM ChallengeTracker WHERE ((strName='" . $strName . "') AND (numMonth=" . $numMonth . "));";
    $dbResult = $wpdb->get_var( $wpdb->prepare( $sqlStr ) );
    fprintf($fh, "SQL: " . $sqlStr . "\n");

    if ($dbResult != NULL) {
    fprintf($fh, "Result returned: " . $dbResult . "\n");
    }

    // We've located the day where
    if ($cnt == $numDay)
    {
    $strDayInfo = "" . $arrMonth[$numMonthIndex] . " " . $cnt . "";
    } else {
    $strDayInfo = $arrMonth[$numMonthIndex] . " " . $cnt;
    }

    if ($dbResult != NULL)
    {
    $choices[] = array("text" => $strDayInfo, "value" => $cnt, "isSelected" => "1");
    } else {
    $choices[] = array("text" => $strDayInfo, "value" => $cnt);
    }

    $inputs[] = array("label" => $arrMonth[$numMonthIndex] . " " . $cnt, "id" => $numFieldID . "." . $i);
    } // End of For Loop

    //Adding items to field id $numFieldID
    foreach($form["fields"] as &$field) {
    if($field["id"] == $numFieldID) {
    $field["choices"] = $choices;
    $field["inputs"] = $inputs;
    }

    [SNIP]

    Posted 12 years ago on Sunday January 22, 2012 | Permalink
  2. Hi, sjolshagen,

    I am closing this topic since we are working with you in a Priority Support ticket.

    Posted 12 years ago on Friday February 3, 2012 | Permalink

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