Condition dropdown - don't save data

Status
Not open for further replies.

medo

New Member
I tried to make similar with your exempel "countries & towns"
but I don't know what I doing wrong :-(

the table with the dropdowns is called: jos_fabrik_formdata_2
the 1st dropdown element?s name is "valg_1"- the 2nd: "valg_2"

first table: gruppe
second table: undergruppe

my elements in the "gruppe" table:
name: id..........................label: id
name: medier......................label: Category

my elements in the "undergrupp" table:
name: id............................label: id
name: media_id......................label: media_id
name: subkategory...................label: Subkategory



I added Java code on 1. dropdown ( onchange ) which is database join element:

*****************

var cid = this.getValue();
var table = 'undergruppe';
var key = 'id';
var label = 'submedia';
var foreignkey = 'media_id';
var dropdown = 'jos_fabrik_formdata_2___valg_2';
var url = 'index2.php?option=com_fabrik&no_html=1&task=userPluginAjax&method=getFields';
url += '&table=' + table;
url += '&val='+cid;
url += '&key='+key;
url += '&label='+label;
url += '&foreignkey='+foreignkey;
new Ajax(url, {
method: 'get',
update: $(dropdown)
}
).request();


*************
*************

Her is User_ajax.php
*************

<?php
/**
* @package fabrik
* @version 905 | fabrik_cheesegrits | 2008-05-19 21:21:05 +0200 (Mon, 19 May 2008
* @Copyright (C) Rob Clayburn
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/

/**
* This is an example file. To use userAjax, copy this file to user_ajax.php,
* and insert your function into the userAjax class, as per the example
* userExists() function. To call your AJAX method, use a URL of this format from
* your custom JS code:
*
* index2.php?option=com_fabrik&no_html=1&task=userPl uginAjax&method=userExists&username=" + myUsername;
*
* Fabrik will automatically try and call the function name specified in your 'method='.
* You are responsible for grabbing any other parameters, using mosGetParams,
* as per the $myUsername exmaple in userExists() below.
*
* The userExists() example is designed to test if a username given in a text element
* exists. If it does, an alert will pop up, then the field will be cleared and the cursor re-focused to it.
*
* The easiest way to call AJAX from your JS is to use the Mootools Ajax class, for instance:
*
* function userExists(myUsername,refocus) {
* var url = "index2.php?option=com_fabrik&no_html=1&task=u serP luginAjax&method=userExists&username=" + myUsername;
* new Ajax(url, {
* onComplete: function(response){
* if (response != '') {
* alert(response);
* refocus.value = '';
* refocus.focus();
* }
* }
* }).request();
*}
*
* In this case, the above code is called from the 'onchange' trigger
* of a text element like this:
*
* var thisElement = $('jos_fabrik_formdata_13___username');
* var myUsername = thisElement.value;
* userExists(myUsername,thisElement);
*
* Note that there may be better ways of doing this, the above is just the way I found
* to get it done. The element JS grabs the content of the text field, and also supplies
* the element object, so the userExists() function can then empty and refocus if the
* specified username already exists.
*
* Another example of using Mootools Ajax might be something like this, which assumes a function
* in this file called buildStateDropDown() (not shown here), which would build the dropdown
* menu for a list of states which you want to update on the fly (for instance if you
* have a "Country" dropdown, and wish to repopulate the State menu when it changes):
*
* function ajaxTest() {
* var url = "index2.php?option=com_fabrik&no_html=1&task=u serP luginAjax&method=getStateDropDown";
* new Ajax(url, {
* method: 'get',
* update: $('jos_fabrik_formdata_13___states')
* }).request();
* }
*
* The important note here is the 'update' parameter, which tells Mootools the ID of the
* form element you want to replace with the AJAX response.
*
*/

/* MOS Intruder Alerts */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class userAjax {

function getFields(){
global $database;
//get all the variables passed in by the ajax objects url
$table = mosGetParam($_REQUEST, 'table');
$key = mosGetParam($_REQUEST, 'key', 'id');
$label = mosGetParam($_REQUEST, 'label', 'submedia');
$foreignKey = mosGetParam($_REQUEST, 'foreignkey', 'media_id');
$val = mosGetParam($_REQUEST, 'val', '1');

//run a query on the database to get the matching fields
$sql = "SELECT $key AS value, $label AS label FROM $table WHERE $foreignKey = '$val'";
$database->setQuery($sql);
$rows = $database->loadObjectList();

//write the results of the query back to the browser - the javascript code will then assign
//the text to the second drop down
foreach($rows as $row){
echo "<option value=\"$row->value\">$row->label</option>";
}
}
}
?>
******************
When I open my form, I choose the options that load the other drop down options,
everything goes well, and then I save the record. After that, in the table view,
only the first drop down shows the correct option, the second drops downs keep
showing "Velg Category", instead of the selected option. If I go to edit again,
only the first drop down shows the selected option. ????

Please help me!! I it one
I tryed in thre days and with Firebug but I not sure that I understend what is returned

Best regards
Medo
 
Can you PM me a backend login and either install JoomlaExplorer or give me ftp details so I can also get at the userAjax.php.

This will save me having to spend ages setting up this test case on my machine.

-- hugh
 
I'm working on the exact same problem on someone elses site. I should be able to answer your question when I fix that one.

-- hugh
 
Yes. Can't find the thread, but basically the second element (the one being changed via AJAX) needs to be a database join element, not a dropdown element. To prevent it filling up with the entire table on a new form, give it a 'WHERE' clause that won't return any data, like "WHERE city = 'foobar'", or whatever would work on your table.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top