4

This might be a bit of a Noob question but here I go:

Using Guest Entries on a site and cannot figure out how to make certain fields required. Those fields are marked as required in the CP but, when using Guest Entries, entries are submitted even when required fields are not filled in.

I can easily implement a front-end validation but I would like the validation to happen on the back-end before saving the entry as well.

  • Should this happen automatically, am I missing something ?
  • Do I have to create a validation "manually" and if so, how ?

EDIT:

After updating the plugin, this is how I displayed validation errors:

{% if entry.errors is defined %}
    {% for errorField, error in entry.errors %}
        {% for errorMessage in error %}
        <ul class="form-errors">
            <li>{{ errorField }} - {{ errorMessage }}</li>
        </ul>
        {% endfor %}
    {% endfor %}
{% endif %}

1 Answer 1

4

If the fields are marked as required in your field layout, then they should fail validation even on the front-end, so it sounds like a bug to me. Can you send a database backup as well as the template code you're using for the form over to [email protected]?

Update

The issue was that if your entries were set to be disabled by default, then Craft won't run any validation on them. Just made a change so that if you use the latest Guest Entries, you'll have an additional plugin setting to enable/disable validation on a per section basis, regardless of the default status of the entry.

4
  • Quick question: I take it Craft not enforcing validation on Draft entries is something you want t kep that way. I guess both oprions make sense here, depending of your conception of draft entriess. Jul 6, 2014 at 12:22
  • Right... drafts are basically "works on progress" and you might want to save them before they are even completed.
    – Brad Bell
    Jul 6, 2014 at 15:28
  • Hey Brad, quick question again. How can I display validation errors on the from end form ? Is the Edit in my original post the best way to do it ? Jul 7, 2014 at 8:27
  • Yup... if you want to get all of errors for the entry, then that'll work fine.
    – Brad Bell
    Jul 7, 2014 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.