Access per field errors in Uniform

Hello,

In @mzur 's Uniform, how can I access the error caused by a specific field in the form? The snippet seems to loop them all. Something like:

<input name="media" type="text" value="<?= $form->old('media') ?>">
    <?php if ( $form->error('media') ): ?>
        // only the error declared for 'media'
    <?php endif ?>

It works if I use array_values :

    array_values($form->error('media'))[0]

I can also use toolkit’s a::first();

    a::first($form->error('media'))

But is there a more Uniform’ish solution ?

Thank you!

I call the snippet like this for every field:

<?php snippet('form/error', ['form' => $form, 'field' => 'email']) ?>

Snippet

<?php if ($form->error($field)): ?>
    <span class="error-text"><?php echo implode('<br>', $form->error($field)) ?></span>
<?php endif; ?>
2 Likes

As @texnixe described, this is in the docs for uniform.

1 Like

Oh that’s true, sorry about it !