Welcome Guest, Not a member yet? Register   Sign In
Multiple Forms on Same Page
#4

Where you load the library/helper doesn't determine where the error messages are displayed. The error messages are displayed wherever you happen to call the function(s) to display them.

If you use the validation_errors() function, it's going to spit out whatever errors are there. So, in this case, you either want to display it in a prominent location on the page which isn't necessarily associated with a specific form, or not use the function at all. Then you use the form_error() function to display the errors on a per-field basis within the form(s), but this will require that the names of the fields in the forms be unique (which isn't a requirement, otherwise).

If you pass a variable back to the page to indicate which form was processed, you could check that before calling validation_errors() on each form (and the form_error() function if you duplicate your field names) to prevent the errors from being displayed on the wrong form(s). I also use the form_error() function to set an error class on my fields so I can use CSS to draw attention to them, like this:

PHP Code:
<div class='control-group<?= form_error("username") ? " {$errorClass}" : ""; ?>'>
    <
label for='username'><?= lang('username'); ?></label>
    <input type='text' name='username' value="<?= set_value('username', isset($record['username']) ? $record['username'] : ''); ?>" />
</div> 
Reply


Messages In This Thread
Multiple Forms on Same Page - by Petersk - 07-27-2016, 11:54 AM
RE: Multiple Forms on Same Page - by cartalot - 07-28-2016, 11:19 AM
RE: Multiple Forms on Same Page - by Petersk - 07-28-2016, 12:10 PM
RE: Multiple Forms on Same Page - by cartalot - 07-28-2016, 03:44 PM
RE: Multiple Forms on Same Page - by mwhitney - 07-28-2016, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB