Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom field validation #71

Open
brandonkelly opened this issue Mar 14, 2017 · 12 comments
Open

Custom field validation #71

brandonkelly opened this issue Mar 14, 2017 · 12 comments

Comments

@brandonkelly
Copy link
Member

No description provided.

@jnaklaas
Copy link

+1

@StijnCoolen
Copy link

Any updates on this? Or any known workaround to make fields required?

@maxfrischknecht
Copy link

+1

@dannystarkDE
Copy link

++1

@umkasanki
Copy link

+++1

@jovanymezura
Copy link

+1

@amityweb
Copy link

amityweb commented Dec 21, 2018

Is there an update on this issue? I find it a bit strange no documentation on how to validate a custom field. Going to be necessary in most forms in custom fields to require something like a phone number. I dont like relying on HTML5 required attribute, nor Javascript, they are not fool proof, so server side is best!

In my particular case I need users to agree to the privacy policy for EU GDPR requirements, so quite important its fool proof!

Thanks a lot!

@shantamg
Copy link

shantamg commented Mar 1, 2019

Here's what I have figured out (Craft 3):

Put this in config/contact-form.php:

<?php
use craft\contactform\models\Submission;

use yii\base\Event;
use yii\base\ModelEvent;

Event::on(Submission::class, Submission::EVENT_BEFORE_VALIDATE, function(ModelEvent $e) {

  $submission = $e->sender;
  $message = Craft::$app->getRequest()->getParam('message');

  if ($message['Custom Field'] != 'perfect response') {
    $submission->addError('custom_field', 'This did not validate');
    $e->isValid = false;
  }

});

?>

@LauraMontgomery
Copy link

+1

@Friksel
Copy link

Friksel commented Apr 15, 2020

+1
The initial issue message is cleared, but if I am not missing something I can't find a solution for showing error messages on custom (message-) fields in the README still to do this without using the event workaround. Being able to validate custom fields like phone number and company feels like pretty basic functionality to me most contact pages have.

Any updates on this?

@jolora
Copy link

jolora commented Sep 15, 2020

+1

1 similar comment
@lennartlott
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests