Hi!
I want to use a dropdown list to sort my data in the frontend.
Let's say I have a lot of records and I only want to show the one with a specific value. One of the input fields in my form is "country".
How can I make a list like this:
Select Country from the list - (dropdown menu here)
This menu should contain a list from countries in my input form.
If I choose "Sweden", it should only display posts where the user had selected Sweden as their country. The field name in the db is "Country" When the selection is made, I want to show the all records (from Sweden) with all other values, such as city etc.
If found this code in another post. I don't know if we can start by modyfing this? When I replace ="orgtype_id" with "country" the result is a blank page, no list, no data.
I want to use a dropdown list to sort my data in the frontend.
Let's say I have a lot of records and I only want to show the one with a specific value. One of the input fields in my form is "country".
How can I make a list like this:
Select Country from the list - (dropdown menu here)
This menu should contain a list from countries in my input form.
If I choose "Sweden", it should only display posts where the user had selected Sweden as their country. The field name in the db is "Country" When the selection is made, I want to show the all records (from Sweden) with all other values, such as city etc.
If found this code in another post. I don't know if we can start by modyfing this? When I replace ="orgtype_id" with "country" the result is a blank page, no list, no data.
<?php
global $database;
$database->setQuery( "SELECT * FROM #__chronoforms_5;" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>";
}
$rows = $database->loadObjectList();
?>
<select name="orgtype_id">
<?php
foreach($rows as $row) {
echo "<option value='".$row->cf_id."'>".$row->orgtype_name."</option>";
}
?>
</select>
<br><br>Post edited by: GreyHead, at: 2008/02/14 12:05
Hi Badola,
If you are going to get user data and then use that to select and display information then you will need two forms (1) to collect the data and (2) to display the selected data*.
In practice you can use a php 'if' or 'switch' to combine these into one ChronoForms form. The html form code looks something like this:
Bob
* Technically you could use Javascript/AJAX to do this on one form but that's not something that ChronoForms directly supports.
** Later - this won't work as it's written you can't get data from a form input and use it in the same form😟 Rubbish!<br><br>Post edited by: GreyHead, at: 2008/03/21 18:27
If you are going to get user data and then use that to select and display information then you will need two forms (1) to collect the data and (2) to display the selected data*.
In practice you can use a php 'if' or 'switch' to combine these into one ChronoForms form. The html form code looks something like this:
<?php
if ( $_POST['country'] == "" ) {
?>
. . . show drop-down to select country . . .
<?php
} else {
global $database;
$sql =
"SELECT *
FROM table_name
WHERE country = '".$_POST['country']."'";
$database->setQuery( $sql );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>";
}
$rows = $database->loadObjectList();
foreach($rows as $row) {
?>
. . . form code to display country info . . .
<?php
}
}
?>
Note that this is pseudo-code and needs development before it will work.
Bob
* Technically you could use Javascript/AJAX to do this on one form but that's not something that ChronoForms directly supports.
** Later - this won't work as it's written you can't get data from a form input and use it in the same form😟 Rubbish!<br><br>Post edited by: GreyHead, at: 2008/03/21 18:27
Thank you Bob.
I wish I knew more about PHP than I actually do...
I have tried to add code for showing the menu, but have no clue of how to display the output. I happy for all the help I can get.
Can you please show me:
1- The code for displaying a listmenu that contains the values of the field "country"
2- The code for displaying all adds that connects to the selected country. For example
These are the openings in Sweden
Ad no1
Title Sales manager
Description
Ad no2
Title Project manager
Description
The first field is called Title and the second Description in the db table
etc.
I wish I knew more about PHP than I actually do...
I have tried to add code for showing the menu, but have no clue of how to display the output. I happy for all the help I can get.
Can you please show me:
1- The code for displaying a listmenu that contains the values of the field "country"
2- The code for displaying all adds that connects to the selected country. For example
These are the openings in Sweden
Ad no1
Title Sales manager
Description
Ad no2
Title Project manager
Description
The first field is called Title and the second Description in the db table
etc.
This topic is locked and no more replies can be posted.