Dynamic select menu

Home Forums Quform WordPress Dynamic select menu

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #8502
    patdundee
    Participant

    Hi Guys

    Is there a way that the select from drop down menu can pull in from a data base using a short code that includes the php script to produce it?

    Many thanks

    p.s. its worth another coffee ๐Ÿ™‚

    ๐Ÿ™‚

    #8573
    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.

    #8586
    patdundee
    Participant

    Hi Ally

    Many thanks for the response.

    Yes that does answer my question ๐Ÿ™‚

    Is that code to go into my custom php script on the page in question where the form is or does it go into the functions php of the theme?

    Did you see my other question? Is there a way of collecting data in a php script when the form is posted to itself?

    Many thanks

    Patrick

    #8592
    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.

    #8620
    patdundee
    Participant

    Hi Ally
    Just to let you know the custom dynamic select works a treat.

    Many thanks
    Patrick

    #8621
    patdundee
    Participant

    Hi Ally

    I have noticed one issue that this causes

    If you go to HERE

    You will see under the form i get an error saying “Please use a valid short code to call snippet.”

    This is a php snippet inserted with XYZScripts PHP Code

    Once you post the form it disappears and works fine. This code is just to display the results after a selection has been sent.

    If i remove your function and manually enter some details into the select box i do not get this error.

    Somewhere along the line the code that is dynamically producing the select option is causing this error for the php snippet.

    Also found another small issue

    Without Ajax post
    When you first load the page the select loads the dynamic list with no issue. Once the form is posted it no longer produces the list in the select box

    It also stops the message display after posting the form from disappearing after the timeout.

    With Ajax post
    It produces the list each time

    Have you any idea how this can be resolved please

    Many thanks
    Patrick

    • This reply was modified 10 years, 3 months ago by patdundee.
    #8628
    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.

    #8629
    patdundee
    Participant

    Hi Ally

    This is the code i use. This works until i use the script to generate the select box. (Table renamed)
    if (isset($_REQUEST['iphorm_7_1'])) {
    $id=$_REQUEST['iphorm_7_1'];
    $res1=mysql_query("select * from myTable where County=$id");
    $showNum=mysql_num_rows($res1);
    if ($showNum>0) {
    echo 'There are '.$showNum.' listed';
    } else {
    echo 'There are currently no shows listed for your chosen county';
    }
    }

    This code is called with the snippet (I have renamed it on here)

    [xyz-ips snippet="My-Snippet"]

    #8631
    patdundee
    Participant

    Hi Ally

    With Debug it shows an interesting error

    WordPress database error: [Table ‘My_Database.wp_comments’ doesn’t exist]

    It is looking for wp_comments in the external database (which i am generating the dynamic select box from in your script)

    This is most likely where the issue lies. as in the dynamic script I use a separate database.

    Hmm tricky, i think with the script the table will possibly have to be in the wordpress database and not an external one.

    What are your thoughts

    Regards
    Patrick

    #8632
    patdundee
    Participant

    Hi Ally
    The new release did fix the other issue ๐Ÿ™‚

    #8633
    patdundee
    Participant

    My thoughts were correct about the database

    I have moved the table to the wp database and it now works correctly with both yours and XYZ snippets.

    I think with an external database I will possibly have to add a separate connection into the wp db file for the external database and then reference this connection in any mySql statements that refer to the external tables.

    regards

    Patrick

    #8634
    patdundee
    Participant

    This just leaves the message display after posting that is not disappearing when you do not use Ajax to post the form

    P

    #8636
    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.

    #8637
    patdundee
    Participant

    That worked ๐Ÿ™‚

    Many thanks once again for all your help ๐Ÿ™‚

    First class as always

    Regards
    Patrick

    #8638
    patdundee
    Participant

    Hi Ally

    Question

    What if you have more than 1 form each having their own dropdown select boxes,

    Would you just rename the function and calls to (for example)

    mytheme_dynamic_dropdown_values_1
    mytheme_dynamic_dropdown_values_2 etc. etc.


    function mytheme_dynamic_dropdown_values_1($form)
    {
    $options = array();
    $res=mysql_query("select * from table ORDER BY name ASC");
    $value="";
    $label="Please select a county";
    $options[] = array('label' => $label, 'value' => $value);
    while ($row = mysql_fetch_assoc($res)) {
    $options[] = array('label' => $row['value'], 'value' => $row['value']);
    }

    $dropdown = $form->getElement('iphorm_8_1');
    if ($dropdown instanceof iPhorm_Element_Select) {
    $dropdown->setOptions($options);
    }
    //mysql_close($conn);
    }
    add_action('iphorm_pre_display_8', 'mytheme_dynamic_dropdown_values_1');

    function mytheme_dynamic_dropdown_values_2($form)
    {
    $options = array();
    $res=mysql_query("select * from table ORDER BY name ASC");
    $value="";
    $label="Please select a county";
    $options[] = array('label' => $label, 'value' => $value);
    while ($row = mysql_fetch_assoc($res)) {
    $options[] = array('label' => $row['value'], 'value' => $row['value']);
    }

    $dropdown = $form->getElement('iphorm_9_1');
    if ($dropdown instanceof iPhorm_Element_Select) {
    $dropdown->setOptions($options);
    }
    //mysql_close($conn);
    }
    add_action('iphorm_pre_display_9', 'mytheme_dynamic_dropdown_values_2');

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