Validate Field to Certain Code

act242

New Member
Good afternoon all.

I am sure this has been answered before - just don't know what to search for.

I want to have a field entitled Competition ID. Users have to enter a certain code in order for the form to be submitted to the database.

Ideally, I would like the field to check a list of codes to see if it validates - but for now I have no clue on how to have it validate just one.

Thanks!
 
The way to do that would be to have you list of valid codes in a table (create a Fabrik list). If it's called (say) "valid_codes", with a field called "code", you would then use a PHP validation plugin that does this:

Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('code')->from->valid_codes->where('code = ' . $myDb->quote($data));
$myDb->setQuery($myQuery);
$results = $myDb->loadResultt();
return !empty($results);

That code will return true (pass validation) if there is a row with a code matching the submitted field's value, and false (fail validation) if not.

If you want each code to only be used some predefined number of times, it would be easy to add a count field to the valid_codes table, and add some code in a PHP form plugin to mark it used, and check for that in the validation as well.

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

Thank you.

Members online

No members online now.
Back
Top