Check submissions on submit

mattsh

Member
I have a simple course registration system in Fabrik.
I use two Fabrik lists, one with the dates for the different courses and the different course types and an other with the registrations. I use the first list as a starting point and use related links to the second lists form for the registrations. The first list is a filtered list to show just courses that havn't passed and to limit registrations.

It all works nearly perfect, except that sometimes I have extra registrations on some courses. What I need is to have a check at form submissons to check the number of registrations on that specific course and if the earlier submissions is more than a preset value {jos_fb_course_max_attend} stop the submission.

I'm not a coding expert so I don't know the best way to solve this.

Thanks!

Regards
Matt
 
So the preset max is on a different table to the form you are submitting, correct? But presumably you have a join element on the form being submitted, which links to the row in the table with the max_attend?

In which case, you'd need to have a custom PHP validation which does something like this:

PHP:
$course_id = $formModel->getElementData('registration___course_id', true);
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT (*) AS total')->from('registration')->where('course_id = ' . $db->quote($course_id));
$db->setQuery($query);
$total = (int) $db->loadResult();

$query->clear();
$query->select('max_attend')->from('courses')->where('id = ' . $db->quote($course_id));
$max = (int) $db->loadResult();
 
return $total > ($max -1);

You'll need to change the element / table / field names to suit.

-- hugh
 
Thanks, but I haven't managed to get it working.

So the preset max is on a different table to the form you are submitting, correct? But presumably you have a join element on the form being submitted, which links to the row in the table with the max_attend?
Correct!

In which case, you'd need to have a custom PHP validation which does something like this:
Feel a bit stupid, but where to put the validation code, have tested the form php plugin and for a single element php validation.

I have changed the code like this
PHP:
$course_id = $formModel->getElementData('registration___registration_date_id ', true);
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT (*) AS total')->from('registration')->where('registration_date_id = ' . $db->quote($registration_date_id));
$db->setQuery($query);
$total = (int) $db->loadResult();
 
$query->clear();
$query->select('registration_max')->from('registration_dates')->where('id = ' . $db->quote($registration_date_id));
$max = (int) $db->loadResult();
 
return $total > ($max -1);

Tested to
Code:
echo $total;
with a element validation and the count is 0 (zero) so I don't think it works. Regards Matt
 
Try changing $course_id to $registration_date_id in that first line.

Also, I think my logic was wrong, the last line should be ...

PHP:
$total < $max

This code needs to go on one of the element's in the registration form, not sure it really matters which one, I'd have to see your form setup.

It goes in the "PHP" box, not the "Condition" box.

If it still doesn't work, put

var_dump($$registration_date_id, $total, $max); exit;

... as the second to last line, and paste the output of that here.

-- hugh
 
O, can you paste the exact code you are running again. If you made that change I said, it really should be working, so maybe there's another issue. Also, fill in your My Sites info (just a backend login, I don't need database or ftp), then if I can't see a problem with the code, I'll log in and take a look. I'll need to know which element the validation is on.

-- hugh
 
Have added a log in data to My Sites.
Have moved the Fabrik "system" to a test site. The element with the validation is workgroup in the Registration list.

Regards
Matt
 
There is still no actual site URL in your My Sites. There is a username and a passord, but no site URL.

Can you just post your URL here, and and I'll go from there. if you don't want it public, let me know, and I'll delete your post as soon as I have the site URL.

-- hugh
 
I can now see the front end, but if I try and log in to the back end, I get redirected to the Upsalla Joint Web Login page, where the credentials you gave me don't work.

I need to get in to the backend of your test site, so I can see and edit the custom code on your validation.

-- hugh
 
Sorry, didn't know that my webhost also set up protection for my test sites admin.
I fix it tomorrow Swedish day time.
 
OK. I'm trying to help, I really am ... just don't seem to be having much luck getting at your site!

BTW, I spent a few weeks at Upsalla way back, in the late 80's, working with the CS department installing a lab full of Xerox network servers and routing gear, as part of a liason between Xerox PARC and the dozen or so top European CS departments. I really enjoyed my time there. Incredibly friendly and hospitable people.

-- hugh
 
Sorry about the delay, it should be fine now to access the adminstrator area.
The site is at bit slow, but Fabrik works fine.

Regards
Matt
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top