Home › Forums › Quform WordPress › Dynamic select menu
- This topic has 15 replies, 2 voices, and was last updated 10 years, 11 months ago by Ally.
- AuthorPosts
- January 29, 2014 at 1:49 pm #8502patdundeeParticipant
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 🙂
🙂
February 4, 2014 at 10:17 am #8573AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 4, 2014 at 11:33 am #8586patdundeeParticipantHi 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
February 4, 2014 at 11:52 am #8592AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 5, 2014 at 1:06 am #8620patdundeeParticipantHi Ally
Just to let you know the custom dynamic select works a treat.Many thanks
PatrickFebruary 5, 2014 at 1:37 am #8621patdundeeParticipantHi 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 boxIt also stops the message display after posting the form from disappearing after the timeout.
With Ajax post
It produces the list each timeHave you any idea how this can be resolved please
Many thanks
Patrick- This reply was modified 10 years, 11 months ago by patdundee.
February 5, 2014 at 10:50 am #8628AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 5, 2014 at 11:05 am #8629patdundeeParticipantHi 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"]
February 5, 2014 at 11:24 am #8631patdundeeParticipantHi 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
PatrickFebruary 5, 2014 at 11:32 am #8632patdundeeParticipantHi Ally
The new release did fix the other issue 🙂February 5, 2014 at 11:37 am #8633patdundeeParticipantMy 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
February 5, 2014 at 11:39 am #8634patdundeeParticipantThis just leaves the message display after posting that is not disappearing when you do not use Ajax to post the form
P
February 5, 2014 at 12:24 pm #8636AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 5, 2014 at 12:38 pm #8637patdundeeParticipantThat worked 🙂
Many thanks once again for all your help 🙂
First class as always
Regards
PatrickFebruary 5, 2014 at 1:07 pm #8638patdundeeParticipantHi 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');
- AuthorPosts
- You must be logged in to reply to this topic.