Get id of record being saved in php validation

chris.paschen

Chris Paschen
I'm trying to create a php validation on an element. (a name element that I need to make sure that the name being entered isn't already used). However, during editing, I need to run the validation but NOT fail for editing the existing record.

The element I'm validating is 'name_pen'.
Which I get via:
$selectedPenName = $data;

I'm doing this via a query:

$query
->select($db->quoteName('name_pen'))
->from($db->quoteName('ked_books_author_profile'))
->where($db->quoteName('name_pen') . " COLLATE UTF8_GENERAL_CI LIKE '".$selectedPenName."'",'AND')
->where($db->quoteName('id') . " != " . $currentPenNameID);​

However, I'm having trouble getting the 'id' value for the record that I'm presently validating (for the 2nd WHERE clause).

What is the proper (most reliable) way to get the value of another field in the current row being edited (during validation)?

I found another forum post that led me to something like this:

$app = JFactory::getApplication();
$model = $this->getModel();
$currentPenNameID = (int) $this->user->get('id');​

But that doesn't seem to work.

I couldn't find anything in the wiki that specifically addressed this (although I wasn't 100% sure what to search on).

If you can point me to a page on the wiki that provides definitive methods of getting values in this situation that would be very helpful.
 
For accessing other form elements (your id element) see the php tooltip
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).

BTW: there's a isuniquevalue validation
 
At this point, if you run across something which you think must be a common requirement in Fabrik, there's probably a plugin or a setting to do it. :)

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

Thank you.

Members online

Back
Top