Default Value Required Dynamic Dropdown

Home Forums Quform WordPress Default Value Required Dynamic Dropdown

This topic is: resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9334
    lawrencepepper
    Participant

    Hello,

    I am dynamically populating a drop down in my form with data from a database.

    This drop down is required.

    I would like for the the First Choice in the drop down to be Choose with a value of null so that it forces the user to use the drop down and choose an option. If they leave it on Choose then then should get the This is Required notice. How to go about this?

    My code to populate the drop down:


    #Populate the Project Dropdown List

    function project_dynamic_dropdown_values($form)
    {
    $options = array();
    $dbc = mysqli_connect('localhost', 'xxx', 'xxx', 'xxx');
    $query = "SELECT * FROM projects ORDER BY description ASC";
    $result = mysqli_query($dbc, $query);

    while ($row = mysqli_fetch_assoc($result)) {
    $options[] = array('label' => $row['description'].' '. $row['machine_number'],'value' => $row['jobnumber']);
    }

    $dropdown = $form->getElement('iphorm_3_9');
    if ($dropdown instanceof iPhorm_Element_Select) {
    $dropdown->setOptions($options);
    }
    }

    add_action('iphorm_pre_display_3', 'project_dynamic_dropdown_values');

    #9337
    lawrencepepper
    Participant

    Figured this out:

    Use this: $options = array(array(‘label’ => ‘Choose’, ‘value’ => ”));

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy