Cascading DropDown with extra Text Field

Kingchen

New Member
Hello,

I have a Cascading Dropdown Menu with all Countries and all Mobile Phone +XXX Codes. Want a extra Field behind the Cascading Dropdown Menu for writing then after the +XXX Code the Number, and after that merge the picked +XXX Code and the Number and Store it in the Database...

Is that Possible, and yes, How?

thx :)
 
If I'm reading this right you want:
Country [dropdown]
XXX prefix [XXX options]
Phone field [_____]
Then you want to store the phone number as XXX-555-5555.

If that's right, you can add another field as calc type and pull in the values: Basically just
$phoneNum = '{tablename___elementXXXname}'."-".'{tablename___elementPHONEname}';
return $phoneNum

The settings in the calc would need to use ajax to adjust on changes. You can either show or hide the element in the form.
(You might need to use _raw in the element name to grab the right value.
 
If I'm reading this right you want:
Country [dropdown]
XXX prefix [XXX options]
Phone field [_____]
Then you want to store the phone number as XXX-555-5555.

If that's right, you can add another field as calc type and pull in the values: Basically just
$phoneNum = '{tablename___elementXXXname}'."-".'{tablename___elementPHONEname}';
return $phoneNum

The settings in the calc would need to use ajax to adjust on changes. You can either show or hide the element in the form.
(You might need to use _raw in the element name to grab the right value.

Hello,

I dont think so.

Now i have this like your Example:
XXX prefix [XXX options]
Phone field [_____]

But i want the the visual style so: ( one line for the menu and a field, not 2 lines )
XXX prefix [XXX options] Phone field [_____]

And for merging, i will test it if that is work for me :)
 
Put the elements in their own group and in the group settings choose 2 columns.
Might not be so close together, but get's them on the same line.
You'll end up with 2 labels this way so,
For the group, you can hide the labels and create a manual label at the start with a display element.
 
Put the elements in their own group and in the group settings choose 2 columns.
Might not be so close together, but get's them on the same line.
You'll end up with 2 labels this way so,
For the group, you can hide the labels and create a manual label at the start with a display element.

Thank you,
But is there a Chance that i can the Second Group intergrate to the 1ste Group? Now i have 2 seperate Boxes... hmmm
 
I think that would require custom coding beyond the features of Fabrik.

Looks like for a Beginner not Possible, but thanks anyway :)


Edit: Another Question: If i select a Item in the Cascading Dropdown List, how can i access to the database and search for the selected item and then the "subitem" like the +XXX Phone Code auto write to another Field Cell that i must just fill the Number after the Country Code?
 
You would need to do this in a calc element. Trigger it via ajax watching the data fields.
You'll find examples with a search here on how to do a database query.
Once you have your value from the query, just return it to end your calc element code - it will be saved in the database as the found value.
 
Looks like its harder then i think :eek:

Added this to Ajax observe field in the Calc Options but didnt work

whats wrong in my code?

my code so far:

$getcountry = (string)'{registration___country}';
$db = JFactory::getDBO();
$query = "
SELECT ".$db->nameQuote('tbl_countries_all_isd_code')."
FROM ".$db->nameQuote('#__tbl_countries_all')."
WHERE ".$db->nameQuote('$getcountry').";
";
$db->setQuery($query);
$result = $db->loadResult();
registration___phone_number = $result;
 
Didn't dig into the whole thread, but at least your last row in calc element should be:
return $result;
not:
registration___phone_number = $result;
 
Didn't dig into the whole thread, but at least your last row in calc element should be:
return $result;
not:
registration___phone_number = $result;

Okey not know this one thanks.

but how can i add then the result "string" into another field like my registration___phone_number field?
 
I would write it a bit different.
You also need to specify fieldToFindIn -> you haven't told it what field to compare and find a matching $getcountry value.

Code:
$getcountry = (string)'{registration___country}';
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
    ->select('tbl_countries_all_isd_code')
    ->from('tbl_countries_all')
    ->where('fieldToFindIn = ' . $myDb->quote($getcountry));
$myDb->setQuery($myQuery);
$result = $myDb->loadResult();
return $result;

I should mention a couple things:
1. You've written tbl_ at the front of your field names -> Fabrik uses a format of tablename____elementname internally. When referencing a field in the database, these are separate things. For database queries, you want to select('elementname') from('tablename').
2. Quote is used to clean user supplied data. If the user is not supplying the elementname you are searching or the tablename you will search, you don't need to quote them - these are hard coded by you, not variables that can be manipulated. It is good practice to do it, but it's messy to read your code.

To push this return value to registration___phone_number field, you'll need to do that with some php in your Form settings Form->Plugins->do->PHP.
Write a similar query to (update instead of select) the table and field (registration___phone_number field) to the value in the calc element above.
 
Last edited:
it's possible.
in element cascading dropdown use Concat Label. Insert Query for filed calculate and concatenate with field table.
Example: (select tbl_countries_all_isd_code.`field` FROM tbl_countries_all_isd_code WHERE tbl_countries_all_isd_code.`ID` = {thistable} .ID),' - ', {thistable}.XXX
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top