Populate Drop Down

Home Forums Quform WordPress Populate Drop Down

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

    Hello, I need to to populate a Dropdown with values from a table in my database dynamically.

    Is this possible with the form builder, if so how do I go about this. I can’t seem to se a way. The dynamic option only allows you to set a default value.

    Thanks.

    L

    #2623
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2652
    lawrencepepper
    Participant

    Hello,

    I think I am close. I am using this but it is not populating the drop down.


    function mytheme_dynamic_dropdown_values($form)
    {
    $options = array();
    $dbc = mysqli_connect('localhost', 'root', 'password', 'user');
    $query = "SELECT * FROM qa_vendors";
    $result = mysqli_query($dbc, $query);
    $data_array = array();
    while ($row = mysqli_fetch_assoc($result)) {
    $data_array[$row['company']] = $row['company'];
    }

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

    add_action('iphorm_pre_display_1', 'mytheme_dynamic_dropdown_values');
    }

    In the form builder I have one option set for the dropdown as it will not et me add the element without an option. Is this the correct way to set up the form for this code to work?

    L

    #2655
    lawrencepepper
    Participant

    I noticed some errors in the above code, fixed it but it still is not working…

    {
    $options = array();
    $dbc = mysqli_connect('localhost', 'root', 'password', 'user');
    $query = "SELECT * FROM qa_vendors";
    $result = mysqli_query($dbc, $query);

    while ($row = mysqli_fetch_assoc($result)) {
    $options[$row['company']] = $row['company'];
    }

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

    add_action('iphorm_pre_display_1', 'mytheme_dynamic_dropdown_values');
    }

    #2656
    lawrencepepper
    Participant

    OK I think I am going crazy, found some more errors… Had my connect statement wrong, eiether way still not working…

    function mytheme_dynamic_dropdown_values($form)
    {
    $options = array();
    $dbc = mysqli_connect('localhost', 'user', 'paswword', 'qa');
    $query = "SELECT * FROM qa_vendors";
    $result = mysqli_query($dbc, $query);

    while ($row = mysqli_fetch_assoc($result)) {
    $options[$row['company']] = $row['company'];
    }

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

    add_action('iphorm_pre_display_1', 'mytheme_dynamic_dropdown_values');
    }

    #2669
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2681
    lawrencepepper
    Participant

    OK,

    Used the code and tested it. It returns:

    Array ( [0] => Array ( [label] => UAB [value] => UAB ) [1] => Array ( [label] => Carleton [value] => Carleton ) [2] => Array ( [label] => Kinsley Inc. [value] => Kinsley Inc. ) [3] => Array ( [label] => Rumsey Eelectric [value] => Rumsey Eelectric ) [4] => Array ( [label] => Cooper Power Division [value] => Cooper Power Division ) [5] => Array ( [label] => Allied Electronics [value] => Allied Electronics ) [6] => Array ( [label] => Dave Inc. [value] => Dave Inc. ) [7] => Array ( [label] => KBI [value] => KBI ) [8] => Array ( [label] => Large Systems [value] => Large Systems ) [9] => Array ( [label] => Ace Hardware [value] => Ace Hardware ) )

    BUT, it is still not showing up in the dropdown on the form.

    #2682
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2683
    lawrencepepper
    Participant

    Ooops. Fixed that but now the page displays blank.

    I am using the code:

    function enterreport_dynamic_dropdown_values($form)
    {
    $options = array();
    $dbc = mysqli_connect('localhost', 'xxx', 'xxx', 'qa');
    $query = "SELECT * FROM qa_vendors";
    $result = mysqli_query($dbc, $query);

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

    $dropdown = $form->getElement('iphorm_1_5');
    if ($dropdown instanceof iPhorm_Element_Select) {
    $dropdown->setOptions($options);
    }
    }
    add_action('iphorm_pre_display_1', 'enterreport_dynamic_dropdown_values');

    #2684
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2688
    lawrencepepper
    Participant

    Getting the error:

    Fatal error: Call to undefined function mysqli_connect() in C:\Users\Administrator\Documents\Websites\QAData\wp-content\themes\dejavu\functions.php on line 46

    Not sure why it is failing now. When I tested just the query and array it returned results fine.

    L

    #2689
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2690
    lawrencepepper
    Participant

    Was thinking same thing. Just fixed. I did not have the Mysqli dll extension enabled in my php.ini file.

    Works like a champ now.

    Thanks so much for all the help!

    L

    #2691
    lawrencepepper
    Participant

    Have a small issue that has come up…

    I am using this code to send some of the form data to a script. One of the data fields is the dropdown box from above that is being dynamically filled.

    function mytheme_post_to_another_script($form)
    {
    // Rewrite the post variables
    $post = array(
    'vendor' => $_POST['iphorm_3_3'],
    'newvendor' => $_POST['iphorm_3_7'],
    'rep' => $_POST['iphorm_3_8'],
    'delete' => $_POST['iphorm_3_11'],
    );

    // Create a new cURL resource
    $ch = curl_init();

    // Set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, 'http://test.gen-techno.com/scripts/vendorupdate.php');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

    // Grab URL and pass it to the browser
    curl_exec($ch);

    // Close cURL resource, and free up system resources
    curl_close($ch);
    }
    add_action('iphorm_post_process_3', 'mytheme_post_to_another_script', 10, 1);

    Now the script no longer works, what is the name of the field string that is now being passed of the drop down, I believe it is not being passed as defined above any longer…

    #2692
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 15 posts - 1 through 15 (of 21 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