Hi,
I'm trying to validate a multi page forms with event switcher.
That's the code in the first First Page
That's the code in the Event Switcher fired on page2
In the "fail" event I put an Event Loop that process the "load" event.
The validation works fine, infact if the input "name" is empty, the first page is reloaded with the warning message "Insert your name" on the top of the form, but the condition "if (!isset($form->errors['name']))" didn't work.
I Try also with "empty" and "array_key_exists" conditions.
What's wrong?
Thanks
I'm trying to validate a multi page forms with event switcher.
That's the code in the first First Page
<?php if (!isset($form->errors['name'])) { ?>
<input name="name" id="name" type="text">
<?php } else { ?>
<input name="name" id="name" type="text" class="error">
<p><?php echo $form->errors['name']; ?></p>
<?php } ?>
That's the code in the Event Switcher fired on page2
<?php
$valid = true;
if ( empty($form->data['name']) ) {
$form->errors['name'] = "Insert your name.";
$valid = false;
}
if ( !$valid ) {
return 'fail';
}
?>
In the "fail" event I put an Event Loop that process the "load" event.
The validation works fine, infact if the input "name" is empty, the first page is reloaded with the warning message "Insert your name" on the top of the form, but the condition "if (!isset($form->errors['name']))" didn't work.
I Try also with "empty" and "array_key_exists" conditions.
What's wrong?
Thanks
Hi fasenderos,
I suspect that the $form->errors array isn't available when the page reloads. If you add a Debugger action in form On Load event you can check what is there.
if the form data is loaded then you could add an entry to $form->data; or you could save it to the User session and check that on load.
Bob
I suspect that the $form->errors array isn't available when the page reloads. If you add a Debugger action in form On Load event you can check what is there.
if the form data is loaded then you could add an entry to $form->data; or you could save it to the User session and check that on load.
Bob
Hi Bob,
of course I have a Debugger action for all my form events 😉
I think the $form->errors is available in the load event for 2 reasons:
[list]1) First the warning message "Insert your name" is taken from $form->errors[/list]
[list]2) The red rectangle named "Errors " of the debugger action says[/list]
I didn't understand what you mean.
If the $form->errors array is available, why I can't use it?
Thanks
of course I have a Debugger action for all my form events 😉
I suspect that the $form->errors array isn't available when the page reloads. If you add a Debugger action in form On Load event you can check what is there.
I think the $form->errors is available in the load event for 2 reasons:
[list]1) First the warning message "Insert your name" is taken from $form->errors[/list]
[list]2) The red rectangle named "Errors " of the debugger action says[/list]
Array
(
[name] => Insert your name.
)
if the form data is loaded then you could add an entry to $form->data; or you could save it to the User session and check that on load.
I didn't understand what you mean.
If the $form->errors array is available, why I can't use it?
Thanks
Ops sorry,
Happy easter🙂 !!
Happy easter🙂 !!
Hi Bob,
not for now.
Andre
not for now.
Andre
Hi
I'm trying with another solution, insted of fire the errors in the $form->errors, I add and entry in the $form->data like this:
Now if I submit the form with empty fields (name or surname), the validation reload the first page and the empty fields have "error" class
The problem is that if I re-submit the form with other errors (for ex. another empty required field), the validation reloads the first page again, but the fields name and/or surname still have the class "error", even if they were not empty, because the entry $form->data['errors'] still exists in the data array.
So I try in the validation to unset the entry if the fields "name" and "surname" are not empty, without success and the $form->data['errors'] continues to exists in the data array.
Thanks
I'm trying with another solution, insted of fire the errors in the $form->errors, I add and entry in the $form->data like this:
if ( empty($form->data['name']) ) {
$form->data['errors']['name'] = "Insert your name.";
$error_count++;
}
if ( empty($form->data['surname']) ) {
$form->data['errors']['surname'] = "Insert your surname.";
$error_count++;
}
Now if I submit the form with empty fields (name or surname), the validation reload the first page and the empty fields have "error" class
<?php if (!isset($form->data['errors']['name'])) { ?>
<input name="name" id="name" type="text">
<?php } else { ?>
<input name="name" id="name" type="text" class="error">
<p><?php echo $form->data['errors']['name']; ?></p>
<?php } ?>
<?php if (!isset($form->data['errors']['surname'])) { ?>
<input name="surname" id="surname" type="text">
<?php } else { ?>
<input name="surname" id="surname" type="text" class="error">
<p><?php echo $form->data['errors']['surname']; ?></p>
<?php } ?>
The problem is that if I re-submit the form with other errors (for ex. another empty required field), the validation reloads the first page again, but the fields name and/or surname still have the class "error", even if they were not empty, because the entry $form->data['errors'] still exists in the data array.
So I try in the validation to unset the entry if the fields "name" and "surname" are not empty, without success and the $form->data['errors'] continues to exists in the data array.
if ( empty($form->data['name']) ) {
$form->data['errors']['name'] = "Insert your name.";
$error_count++;
} else {
unset ($form->data['errors']['name']);
}
if ( empty($form->data['surname']) ) {
$form->data['errors']['surname'] = "Insert your surname.";
$error_count++;
} else {
unset ($form->data['errors']['surname']);
}
Thanks
Hi Andre,
If you are only checking for empty inputs have you tried using the Server Validation action?
I'm not clear where your custom code is in your form?
Bob
If you are only checking for empty inputs have you tried using the Server Validation action?
I'm not clear where your custom code is in your form?
Bob
Hi Bob,
I'm checking also for custom validations such as vat number, date format, personal id number etc.
I have a multipage form with 4 events (load, page2, page3, submit), and I use three Event Switcher: one in page2 to validate the first page, one in page3 to validate the second page and last in submit to validate the third page..
Validation works fine and I'm able to validate all fields as I need...the problem is that I would like to "add" (in php, no JavaScript) a different class to the input not validated, instead to show the standard joomla warning at the top of the form
Thanks
Andrea
I'm checking also for custom validations such as vat number, date format, personal id number etc.
I have a multipage form with 4 events (load, page2, page3, submit), and I use three Event Switcher: one in page2 to validate the first page, one in page3 to validate the second page and last in submit to validate the third page..
Validation works fine and I'm able to validate all fields as I need...the problem is that I would like to "add" (in php, no JavaScript) a different class to the input not validated, instead to show the standard joomla warning at the top of the form
Thanks
Andrea
Hi Bob,
I managed to figure out where is the problem. The problem is in the "Multi Page" action, if is set to YES "Reset any stored data" the validation works fine, if is set to NO, it works only the first time (add correctly the error class). After the first time, it always load input with error class, also if input isn't empty, that's because the $form->data['errors']['input_name'] still exist also if I destroy the entry with unset.
I created a demo to illustrate the problem.
1) Try first to go to the second page leaving all fields empty, then leaving one field empty and then filling all fields. Do the same thing in the second page.
2) Now try the same routine as before, but with "Multi Page" action set to NO on page2 event.
Thanks
I managed to figure out where is the problem. The problem is in the "Multi Page" action, if is set to YES "Reset any stored data" the validation works fine, if is set to NO, it works only the first time (add correctly the error class). After the first time, it always load input with error class, also if input isn't empty, that's because the $form->data['errors']['input_name'] still exist also if I destroy the entry with unset.
I created a demo to illustrate the problem.
1) Try first to go to the second page leaving all fields empty, then leaving one field empty and then filling all fields. Do the same thing in the second page.
2) Now try the same routine as before, but with "Multi Page" action set to NO on page2 event.
Thanks
This topic is locked and no more replies can be posted.