# Uniform for Kirby require checkbox to be checked

**URL:** <https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 23, 2018, 7:09pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885 "2018-07-23T19:09:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elhodel](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@elhodel](https://forum.getkirby.com/u/elhodel)\
**Post date:** [July 23, 2018, 7:09pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/1 "2018-07-23T19:09:01Z")

</div>

Hi

I’m using Uniform for Kirby to add an Contact Form to a site. There i need the user to accept the privacy policy. If he does not he should be unable to send the form.  
If i simply say ‘required’ in my rules, i can never send the form, and if i write nothing i can naturally always send the form.  
How can i test if the user checked the checkbox for the privacy policy?

My Controller:

```
<?php

use Uniform\Form;

return function ($site, $pages, $page)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Geben sie eine gültige E-Mail-Adresse an',
        ],
        'telefon' => [
            'rules' => [],
        ],
        'name' => [
            'rules' => ['required'],
            'message' => 'Geben sie Ihren Namen an',
        ],
        
        'strasse' => [
            'rules' => [],
        ],
        'ort' => [
            'rules' => [],
        ],
        
        'message' => [
            'rules' => ['required'],
            'message' => 'Hinterlassen sie eine Nachricht',
        ],
        'datenschutz' => [
            'rules' => [],
            'message' => 'Sie müssen die Datenschutzbestimmungen akzeptieren',
        ],
    ]);

    if (r::is('POST')) {
        $form->emailAction([
                'to' => 'info@example.com',
                'from' => 'info@example.com',
                // Dynamically generate the subject with a template.
                'subject' => 'Neue Nachricht',
            ])
            ->logAction([
                'file' => kirby()->roots()->site().'/registrations.log',
            ])
            ->emailAction([
                // Send the success email to the email address of the submitter.
                'to' => $form->data('email'),
                'from' => 'info@example.com',
                // Set replyTo manually, else it would be set to the value of 'email'.
                'replyTo' => 'info@example.com',
                'subject' => 'Kontakt KL',
                // Use a snippet for the email body (see below).
                'snippet' => 'emails/success',
            ]);

        if ($form->success()) {
            //go(page('registration/success')->url());
        }
    }

    return compact('form');
};

?>

```

My Template:

```
<form class="contactform <?php if ($form->success()) echo "success"; ?>" id="form" action="<?php echo $page->url()."#form" ?>" method="POST">
    <?php if ($form->success()): ?>
    Vielen Dank für Ihre Nachricht!
    
    <?php endif;?>
    
    
    <hr>
    <div class="contactform_line">
    <label>Email*</label>
    <input<?php if ($form->error('email')): ?> class="error"<?php endif; ?> name="email" type="email" value="<?php echo $form->old('email') ?>">
    <?php snippet('form/error', ['field' => 'email']) ?>
    </div>
    <hr>
    
     
    <div class="contactform_line">
    <label>Name*</label>
    <input<?php if ($form->error('name')): ?> class="error"<?php endif; ?> name="name" type="text" value="<?php echo $form->old('name') ?>">
   
    <?php snippet('form/error', ['field' => 'name']) ?>
    </div>
    
    <hr>
    <div class="contactform_line">
    <label>Strasse</label>
    <input<?php if ($form->error('strasse')): ?> class="error"<?php endif; ?> name="strasse" type="text" value="<?php echo $form->old('strasse') ?>">   
    <?php snippet('form/error', ['field' => 'strasse']) ?>
    </div>
    
    <hr>
    <div class="contactform_line">
    <label>PLZ / Ort</label>
    <input<?php if ($form->error('ort')): ?> class="error"<?php endif; ?> name="ort" type="text" value="<?php echo $form->old('ort') ?>">
    <?php snippet('form/error', ['field' => 'ort']) ?>
    </div>

    <hr>
    <div class="contactform_line">
    <label>Telefon</label>
    <input<?php if ($form->error('telefon')): ?> class="error"<?php endif; ?> name="telefon" type="tel" value="<?php echo $form->old('tel') ?>">   
    <?php snippet('form/error', ['field' => 'tel']) ?>
    </div>
    
    <hr>
    <div class="contactform_line">
    <label>Nachricht*</label>
    <textarea id="textarea" rows="3"<?php if ($form->error('message')): ?> class="error"<?php endif; ?> name="message"><?php echo $form->old('message') ?></textarea>
    <?php snippet('form/error', ['field' => 'message']) ?>
    </div>

    <?php echo csrf_field() ?>
    <?php echo honeypot_field() ?>
    
    <hr>
    <div class="contactform_datenschutz checkbox">
        <input<?php if ($form->error('datenschutz')): ?> class="error"<?php endif; ?> name="datenschutz" type="checkbox" value="<?php echo $form->old('datenschutz') ?>"> 
        <label> Ich akzeptiere die Datenschutzbestimmungen.</label>
    </div>
    
    
    <input type="submit" value="Senden">
    <!-- Show errors of the email actions if there are any -->
    <?php snippet('form/error', ['field' => \Uniform\Actions\EmailAction::class]) ?>
</form>

```

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [July 23, 2018, 8:24pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/2 "2018-07-23T20:24:15Z")

</div>

Im not sure i understand. It needs to be required to prevent submission. That is the test!

---

<div class="post-metadata">

**Author:** ![elhodel](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@elhodel](https://forum.getkirby.com/u/elhodel)\
**Post date:** [July 23, 2018, 8:35pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/3 "2018-07-23T20:35:46Z")

</div>

that is my understandig as well.  
but when do make it required i can not submit at all: even if i check the checkbox…

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [July 23, 2018, 8:39pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/4 "2018-07-23T20:39:43Z")

</div>

I have such a rule on my site for GDPR that I know works… maybe comparing it helps…

The controller has this in it:

```auto
'gdprconsent' => [
        'rules' => ['required'],
        'message' => "Your consent is required.",
      ],

```

And the HTML looks like…

```auto
<div class="block-1 consent-box <?php if ($form->success()): ?>completed<?php endif; ?>">
<div class="block-col">
<h3>Important</h3>
<p>To comply with new data protection laws (<a href="https://ico.org.uk/for-organisations/guide-to-the-general-data-protection-regulation-gdpr/" target="_blank">GDPR</a>), we require your consent to record and retain your contact details. How this information is used and stored is explained within our <a href="<?= $site->file('hashandsalt-privacy-policy.pdf')->url() ?>">Privacy Policy</a>.</p>
<div class="fancy-checks">
<input <?php if ($form->error('gdprconsent')): ?> class="error"<?php endif; ?> type='checkbox' name='gdprconsent' value='consent' id="gdprconsent" />
<label for="gdprconsent">I consent to my contact details being recorded and retained.</label>
<?php if ($form->error('gdprconsent')): ?>
<p class="form-error-hint"><?= implode('<br>', $form->error('gdprconsent')) ?></p>
<?php endif; ?>
</div>
</div>
</div>

```

I think you might be using an old version of uniform… your syntax looks a bit odd. I am not sure this is right…

```auto
<?php snippet('form/error', ['field' => \Uniform\Actions\EmailAction::class]) ?>

```

Did you follow the Uniform documentation or do something special?

---

<div class="post-metadata">

**Author:** ![elhodel](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@elhodel](https://forum.getkirby.com/u/elhodel)\
**Post date:** [July 23, 2018, 8:54pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/5 "2018-07-23T20:54:29Z")

</div>

thanks! i will have a close look at your example tomorrow!  
most of the code i copyed from the “extended tutorial” from the documentation here: [http://kirby-uniform.readthedocs.io/en/latest/examples/extended/](http://kirby-uniform.readthedocs.io/en/latest/examples/extended/)

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [July 23, 2018, 9:01pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/6 "2018-07-23T21:01:09Z")

</div>

You should upgrade and follow this page instead (I think)…

[https://kirby-uniform.readthedocs.io/en/v3.4.0/examples/extended/](https://kirby-uniform.readthedocs.io/en/v3.4.0/examples/extended/)

Although latest should mean latest 🙂 Looks like the latest version is [3.4.0](https://github.com/mzur/kirby-uniform/releases).

---

<div class="post-metadata">

**Author:** ![elhodel](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@elhodel](https://forum.getkirby.com/u/elhodel)\
**Post date:** [July 23, 2018, 9:07pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/7 "2018-07-23T21:07:11Z")

</div>

ah i figuered it out!  
i copypasted the input field and only changed the type but left  
`<input ... type="checkbox" value="<?php echo $form->old('datenschutz') ?>">`  
it should be  
`<input ... type="checkbox" value="consent">`

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:26pm UTC](https://forum.getkirby.com/t/uniform-for-kirby-require-checkbox-to-be-checked/10885/8 "2025-02-06T17:26:43Z")

</div>

Archived on February 6, 2025, 5:26pm UTC


