PHP validation rule on a field element

wuschel_lux

Member
Hi all,

are php validation rules acting the same if used in an "element" or "form"?

I have personalised generated link:
https://url.me/evaluation?tab_form___my_hash=9EZlf6Z8EcOAGSJ&tab_form___course=48
send out to the participant.

The system now needs to check if the Hash is in a table and the evaluation form is still open. Both info are found in an SQL table.

I tried this code:
PHP:
$mydatabase = JFactory::getDBO();

// values from this form
$coursID = $this->data['tab_form___course_raw'];
$myHash  = $this->data['tab_form___my_hash'];

// value from other table
$sql = "
  SELECT *
  FROM evaluation_buffer
  WHERE id = '$coursID'
";
$mydatabase->setQuery( $sql );
$rows = $mydatabase->loadObjectList();
  foreach ( $rows as $row ){
    $myHash_buffer  = $row->my_hash;
  }

// check if both hash values are equal
if($myHash_buffer == $myHash){retun 'true';} else retun 'false';

When trying to go to the next tab in the form, the validation is hanging and an error is shown:
[Error] Failed to load resource: the server responded with a status of 500 () (index.php, line 0)
https://url.me/index.php?option=com_fabrik&format=raw&task=form.ajax_validate&form_id=9 simular to this issue:
https://fabrikar.com/forums/index.p...running-in-validation-loop.53779/#post-281162

Now is this the same problem, or is my php code maybe wrong.

Hope someone can help me out. Thanks
 
Yes, you have a syntax errors in your code (missing brackets, retun instead return). Test with https://phpcodechecker.com/

And your code logic is also unclear for me. I see you are looping through several hashes which are returned by you query, so only the last result in your loop will be set for comparing. Are there actually multiple hashes for one course id? If yes then you probably need to get the latest one from query like: SELECT ....... ORDER BY id DESC LIMIT 1 and drop the "foreach" loop.

And remove the single quotes from around true and false.

You may have more problems, but these are the things that straight "popped into my eye" at the moment.
 
Last edited:
there's no validation php rule on forms, only php plugin ( where you can do what you want, including validations).
If you get sticky spinners somewhere check in your browser dev tools for error messages in console AND in network responses.

Gesendet von meinem SM-G930F mit Tapatalk
 
many thanks for the quick answers.
Autsch! I corrected the typo and the error is gone, I refined the query and it works now as it should
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top