Forums

Validate condition(s), if fail stop processing form

wayne.regehr 10 Sep, 2014
I have made a 'Events' form that will take registration and payment for various events. The form requires a user to enter some information for registration (name, phone, email, address, etc) and enter the number of tickets they would like to purchase.

The form itself is functioning as intended with one small issue. I require testing for a specific condition, whether there are enough tickets remaining/available to process the payment.

The logic for this validation boils down to if there are enough tickets, continue processing the form. If there are not enough tickets available, then stop processing the form (similar to an incorrect Captcha code). I would prefer that this validation be php based and not js.

I am able to code the php validation, but am a little lost as to how to stop the form from processing. Any ideas or suggestions would be greatly appreciated.
wayne.regehr 10 Sep, 2014
So I discovered the 'Event Switcher' action and did some research on how to implement it for validation.

My code the Event Switcher is as follows:

<?php
// Tickets Available - Tickets Requested
$ticketCalc = $form->data['ticketsAvailable'] - $form->data['quantity'];

if ($ticketCalc >= 0) {
	return "success";
}
else {
	$form->errors[] = $config->get('error', 'There are not enough tickets available. Please adjust your Ticket Quantity and re-submit.');
	return "fail";
}
?>


My PHP code is valid however when processing the form, it now goes to a blank screen once my validation is processed. I added a 'Debug' action to the on submit to see what was going on. The Debug output was as follows:


Data Array
Array
(
    [chronoform] => events_form
    [event] => submit
    [k2_itemId] => 326
    [event_name] => Paid Event Testing
    [first_name] => Sean
    [last_name] => Regehr
    [phone] => (403) 923-0897
    [email] => mr.sean.regehr@gmail.com
    [address] => 39 West Terrace Drive
    [city] => Cochrane
    [province] => AB
    [country] => Canada
    [postal_code] => T4C 1R5
    [ticketPrice] => 1.00
    [ticketsAvailable] => 9
    [item_name] =>  Tickets: Paid Event Testing
    [ticket_quantity] => 20
    [total_ticket_amount] => 20.00
    [captcha] => e7myk
    [event_submit] => Submit
    [view] => item
)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
)


Based on the Debug action output I am lost as to what is causing the blank page (form).

In case this information helps I will include the actions for the 'On Submit' event.
[list=]
Debugger
Event Switcher (if success continue, if fail event loop)
Check Captcha (if success continue, if fail event loop)
DB Save
Email
PayPayl Redirect
[/list]

If I can provide any other information, just let me know. I will update this thread with any new information or progress made.
Max_admin 12 Sep, 2014
1 Likes
This line:
$form->errors[] = $config->get('error', 'There are not enough tickets available. Please adjust your Ticket Quantity and re-submit.');

should be:
$form->errors[] = 'There are not enough tickets available. Please adjust your Ticket Quantity and re-submit.';


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
wayne.regehr 12 Sep, 2014
Answer
1 Likes
Max,

Thanks for the assistance.

I found a stupid mistake on my part.
$form->data['quantity']

should have been
$form->data['ticket_quantity']

You know you've been looking at the screen too long when..

Consider this closed.
This topic is locked and no more replies can be posted.