Questions tagged [validation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
1answer
349 views

Craft 3 Custom Plugin: model validation

Struggling a bit here - have created a custom plugin where I want to validate form submission against a predefined model before saving to the database. All pretty straightforward so far … However, if ...
1
vote
1answer
13 views

Normalize then validate unique entry in a custom module field

I have a custom text field in a module that the user populate with an EAN number. The input is getting validate by a "match" validator and then is serialized before save to get ride of the various ...
1
vote
1answer
23 views

Server-side address validation in Craft Commerce 3

Was wondering how to do this in Commerce 3 as there were a few different older methods discussed here.
1
vote
1answer
46 views

Frontend form validation

I need to validate the form submitted at the frontend by applying additional validation rules. For that I have created the plugin that listens to "EVENT_BEFORE_SAVE_ENTRY" event and should validate ...
1
vote
0answers
20 views

Sanitize form input

I'm trying to sanitize form input values in my plugin. Yii2 framework provides the following validation method: https://www.yiiframework.com/doc/guide/2.0/en/tutorial-core-validators#filter It says ...
1
vote
1answer
44 views

How do I show errors for a new front end entry form?

I'm using a front end form so logged-in users can create a new entry ("post") or edit an existing entry. Here's the controller for figuring out whether it's a new or existing entry: {# Get the entry ...
0
votes
0answers
16 views

entry-field that is only editable on entry-creation and contains unique string

I have a text field that is used as a text-handle for linked entries. So it must not be changed after other entries reference it. It should be editable only on the creation of the entry and validated ...
1
vote
1answer
312 views

How to validate a form request

Is there anything with craft like Laravel's Form Requests? I am writing a plugin with a custom entry type. Right now, I am doing the store/edit pages and I do not want to reinvent the wheel ;) Is ...
1
vote
1answer
33 views

Field formatting

I'm looking for a way to restrict how a field gets formatted. I have a channel for a podcast that should always be in the format of hh:mm:ss - despite the instructions making this clear, editors tend ...
1
vote
1answer
150 views

Craft Rules and Validation

Some of the changes in craft 3 have been killing me. I know Yii does validation using the public rules function. Here is a rules function I grabbed from the MatrixBlockType model. function rules() { ...
1
vote
1answer
69 views

Do field values get serialized before validation?

I am learning to write my first plugin for Craft CMS 3.x I have a field that gets displayed as a string, but is stored in the database as binary. When I validate it, I write: public function ...
3
votes
2answers
166 views

Validation on username?

Just wondering if theres anyway to force some validation on the username? I have usernames being displayed locally, and therefore I'm trying to prevent email addresses being used. I have my client ...
2
votes
1answer
263 views

How to validate a unique field in Craft 3 element?

I'm trying to validate a custom Element in my Craft 3 plugin. Where should I be putting my validation rules? I have two classes: one for the Element, one for the ActiveRecord (e.g. Invoice and ...
1
vote
1answer
89 views

How can I set a custom URI for the confirmation link of account email update from a front-end form?

I have a front-end form to update user's email address, like this example: <form method="post" accept-charset="UTF-8" enctype="multipart/form-data"> {{ csrfInput() }} <input type="...
2
votes
2answers
203 views

Craft Commerce: make address phone telephone field required without JavaScript

Because I used a similar address model to the one supplied in the Craft Commerce templates, which essentially uses the same form partials for both address and billing, and also hides and shows the ...
1
vote
2answers
398 views

Craft Commerce — Billing / Shipping Address validation / required Fields

As default Craft has only First Name and Last Name as required. Is it possible to set more as this two fields as required fields? And is it also possible to set custom Fields as required too?
1
vote
2answers
212 views

Validating Date of Birth format from a form field value

I'm working a on website project which includes a web form which asks for various personal details, one of the fields on the form is Date of Birth. The form is being validated by a custom plugin ...
2
votes
1answer
323 views

Title field character length

Is it possible to limit the title field in an entry? As with other fields I can adjust so that it only takes a certain amount of characters.
6
votes
1answer
1k views

How can I add custom validation rules to my plugin settings?

I have a plugin that needs to perform some custom validation on one of its settings. How would I go about doing that?
1
vote
1answer
370 views

`entry` variable pre-populated on a frontend form

I set up a single page "Add Post" in the CP. In following the example here https://craftcms.com/docs/templating/entry-form my form title input field is pre-populated with "Add Post" This is obviously ...
1
vote
1answer
140 views

Show all form errrors using amforms

I'm using amforms and would like to display all form errors at the top of my page, not just per field. I can't seem to find the answer in the docs. Is this option available?
2
votes
1answer
450 views

How can I validate a Redactor rich text field in a front-end form using the VeeValidate Vue.js plugin?

Scenario I'm using the VeeValidate Vue.js plugin to validate a Craft front-end form that contains a Redactor rich text field. Problem Validation of the rich text field fails because Redactor adds ...
1
vote
1answer
188 views

AttributeType::Number giving validation error “Must be an integer”

So I have a model attribute attributeName with an AttributeType::Number I haven't implemented any personal validation rules yet, however when I run: model->validate(), its giving me a "...
2
votes
1answer
53 views

onBeforeSaveUser event does not fire if basic user fields do not validate

I have additional fields I check for in the onBeforeSaveUser event and add the errors to the errors array. The problem is my code doesnt even run if they miss the main fields or if the email is ...
1
vote
1answer
161 views

AttributeType::Handle Validation and Unique

I'm building a plugin that has a column in the DB which is unique and essentially an AttributeType::Handle. Here is the piece from the record: return array( 'key' => array(AttributeType::...
2
votes
1answer
506 views

Entries Field Type Validation

I am having some issues understanding why validation is not working on my entry forms. I've got an entry with several field types which aren't of type "entries" and the required validation is working ...
1
vote
0answers
86 views

How to set other fields as required in Craft Commerce checkout process? [duplicate]

I'm using Craft Commerce with the default checkout template. At the step of completing addresses, only First Name, Last Name & Country are required fields by default. As I'll sell non-digital ...
0
votes
5answers
913 views

You don’t have the proper credentials to access this page

when trying to insert a guest entry i get the following response from craft: You don’t have the proper credentials to access this page. What can i do to avoid this and still insert the entry to craft?...
2
votes
2answers
193 views

Front-end registration validation

I have a front-end registration page and need to change the validation to add (minimum characters for information on the page and to make fields to accept only letters and other to accept only number ...
1
vote
1answer
121 views

Change password on user profile (customer account in Craft Commerce)

I have a customers area as part of the Craft Commerce site I am working on. Ideally I want the user to be able to update their password from their customer profile screen. I have it working and ...
1
vote
1answer
299 views

Password validation for resetting password

I have the following code to further validate passwords when creating/registering an account which is working fine. However, when trying to use this same validation for resetting a password I am not ...
4
votes
2answers
163 views

How do I include record relationships in validation?

Say I have a record defining a foreign key relationship which is set to required, such as: public function defineRelations() { return [ 'type' => [ static::BELONGS_TO, ...
3
votes
1answer
425 views

Craft Commerce: Custom address model validations

How/Where/Can I add more address model validations than just "firstName" and "lastName"...?
0
votes
1answer
388 views

Front-end entry field validation problem

I have this simple code: <form method="post" accept-charset="UTF-8"> <input type="hidden" name="action" value="entries/saveEntry"> <input type="hidden" name="redirect" value="...
3
votes
1answer
455 views

How do I write custom model validators for my plugin that refer to other fields?

I'm looking at this guide to writing custom validators: https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-5-custom-validators However, this only allows code that refers ...
1
vote
1answer
664 views

Form field validation

I am relatively new to Craft CMS and have been using the formBuilder2 plugin to create forms. No problem this far. I have been able to use ElementApi to output the forms into Json. Still no problem. ...
0
votes
1answer
108 views

Custom Validation Message for numeric

I want to Number validation for my site, but not able to show custom validation message to user. 'CVV' => [ 'label' => 'CVV Number', 'type' => 'numerical', ...
1
vote
3answers
643 views

Customise errors when validating model data?

I’m trying to set a custom message for a specific model attribute. I have something like this: protected function defineAttributes() { return array( 'attributeOne' => array( ...
1
vote
1answer
69 views

Model validation not run when using EntriesService saveEntry method

Currently i have to validate my model before saving because of some custom validation rules setted on the model which won't run when using the EntriesService saveEntry method. This causes a two step ...
3
votes
1answer
333 views

How can I repopulate a matrix field on a front-end form?

I have a matrix field on my front-end form. Everything is working properly, data is saved correctly etc. I am testing & trying to break things and I noticed I wasn't repopulating those fields if ...
2
votes
3answers
188 views

Entry validation not working when Publish live changes permission is not checked

when a user with no permission to publish is submitting a blank entry, the entry is saved anyway without any errors. Here is the permissions set to the user group: I have few required field as ...
1
vote
1answer
251 views

How can I repopulate my dropdown on a front-end form?

I am allowing guest registrations - everything is working fine. I am hung up on getting my drop down menu to repopulate/hold its value if there are any errors while submitting. I have a states field ...
1
vote
1answer
243 views

Validating date fields in a plugin's settings

I have a plugin that has some settings, some of which are dates. I want to make these fields required, and ensure they are valid dates. Because of this bug the date attributes are set as ...
6
votes
3answers
3k views

Programmatically update entry field

I'm trying to update an entry's field value from a Craft plugin. First I was trying to just update the attributes of the entry like so: $entry->getContent()->setAttributes(array( 'metaStatus' ...
0
votes
1answer
197 views

How can I make a product field required?

I have a drop-down of variants of a product. For example t-shirts: {% for purchasable in product.variants %} <option value="">Select</option> <option {% if purchasable.stock &...
2
votes
1answer
119 views

Handling non-image uploads when updating user photo from front-end form

We have a front-end form that allows users to update their profile photo. If a user attempts to upload a non-image file, instead of the actionSaveUser controller failing and throwing an error, it gets ...
1
vote
1answer
272 views

How to make a mixed field type required

From this incredibly helpful validation article(s), I found that: AttributeType::Mixed does not apply any validation rules Ok cool. I am using two fields that are DateTime fields, but due to a ...
1
vote
1answer
326 views

Custom validation rules on frontend form

What would be the best way to add some custom validation rules on forms submitted on the front-end without using specific field types for it? I'm using the Guest Entries plugin that allows anonymous ...
2
votes
2answers
433 views

Passing data back to form on invalid submission

I currently have a form that is being displayed to the user via a custom route. The form submits to a controller. The first thing the controller does is populate a custom model and validates it. If ...
0
votes
1answer
148 views

Base fieldtype validation working with model validation?

How can you ensure that the base fieldtype validation (required etc) and error messages are still applied when validating $value via the validate($value) function?? Validate method in fieldtype class:...