• New Commercial Services Section

    We have now opened a commercial services section here on the forum. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.

    Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.

Placeholder for the current row ID selected

jmdc

Member
Hello,

I am trying to do a query like

SELECT elementname FROM table WHERE "row ID selected/clicked/in form view", userid={$my->id}?

Is there any placeholder for "active row ID"?

Thank you.
 
I am trying to have a php code like this:

$db2 = JFactory::getDbo();
$myQueryb = 'SELECT DebitarFacturas FROM esc_familiasdet WHERE {rowid} = ???selectedROW??';
$db2->setQuery($myQueryb);
$dtb = $db2->loadResult();

I will use $dtb for IF statements. This is for a php validation in a radiobutton element,

What can i have to put in WHERE condition?

Thank you for your attention.
 
Usually
$myQueryb = 'SELECT DebitarFacturas FROM esc_familiasdet WHERE id={rowid}';
Assuming "id" is the element name of your internalid element.

Not sure if it's doing in the validation, try it.

Other way as the tooltip says: "The PHP code to run. This element's value is in $data. Other element values can be found in $_REQUEST (use JFactory::getApplication()->input->get() to access). Return either true/false (if 'match' selected below) or the replacement string (if 'replace' selected below)."
 
I tried the first solutin but it doesn t work.

Using the tooltip, is this correct?

$input->get('foo', 'default', 'string');
return $dtb == JFactory::getApplication()->input->get('esc_familiasdet___id');

Thank you.
 
OK, {rowid} does work as a placeholder. Here's a view of my debugger, showing the code that actually does that validation:

http://screencast.com/t/d1JUQXp1t5HD

... as you can see, rowid is set in the $formData array, and is being replaced into the code to be eval'ed.

HOWEVER ... note that on a new form, as opposed to editing a form, that rowid won't exist, because validation happens before the data is written to the database. So you'd need to detect that in your code, and not run your query if the rowid is empty something like ...

Code:
$myrowid = '{rowid}';
if (!empty($myrowid)) {
   /// your code goes here
}
else {
   return true;
}

But I'm slightly confused as to why you would be looking up data from the same row in the same table, unless you are trying to detect if data has been changed?

-- hugh
 
OK, in which case you don't need to look the data up, we already load the original row data into $formModel->origData. So you could just do something like this ...

Code:
if (!empty($formModel->origData)) {
   $your_element = $formModel->origData[0]->yourtable___your_element;
   // do whatever you need to do with your_element's original value
}

Note that origData is an array, which may have more than one entry if you have joined data. But the main table's data will always be in origData[0], which will be an object keyed by full element name.



-- hugh
 
I?m really confused with all that....

What i want to do in my php plugin validation is a 3 conditions statement like
1) if value(elementA) from that rowid selected = 1
2) and if old.value(elementB) = 1
3) and if $data (new value for elementB) = 0, then return FALSE.

How can i have 2 or more queries (select from where....) in one php statement, with 2 or more variables defined with an if condition like:

if(($valueelementA == $oldvalueelementB == '1') && $data == '0'){
return false;
}
else{
return true;
}

I am trying this for days, but i?m really not able to do it....:( I have no much knowledge of php language....:(

Thank you.
 
Try something like ...

Code:
if ($formModel->formData['yourtable___elementA'] == '1' && $formModel->origData[0]->yourtable___elementB == '1' && $data == '0') {
   return false;
}

Although depending what element types A and B are, the data may be arrays.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top