First I illustrate the way I set up guest entry form.
Let's say I have channels blog
product
and comment
cart
.
Guest entry submits to the comment
cart
channel. Form lives in template which I use to show blog's product's entry.
Now I just send required field title which won't get passed by validation unless it isn't blank.
According to Guest Entries settings to show my blog's product's content along with my guest entry form I have to change the name of entryVariable
key from entry
to whatever not taken variable name let's say entryError
in an event of validation error to not overwrite blog's product's variable entry
.
In short this is how the template looks like when blog product entry load. This is just part of the form which is executed when first item is added to the cart
matrix field in cart
channel.
{# Product's title #}
{{ entry.title }}
{# Product's text #}
{{ entry.text }}
{# Show form error #}
{% macro errorList(errors) %}
{% if errors %}
<ul class="errors">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% from _self import errorList %}
<form method="post" accept-charset="UTF-8">
{{ getCsrfInput() }}
<input type="hidden" name="action" value="guestEntries/saveEntry">
<input type="hidden" name="sectionId" value="2">
<input type="hidden" name="title" value="Some dynamic title">
{# Matrix field "cart" #}
{# Block type field we want the product to save in. #}
<input type="hidden" name="fields[cart][new1][type]" value="product">
<input type="hidden" name="fields[cart][new1][fields][productTitle]" value="{{ entry.title }}">
{# Quantity #}
<label>Quantity *</label>
<select id="qntySlct" name="fields[cart][new1][fields][productQuantity]">
<option value="">--Please, select the quantity--</option>
{% for i in 1..10 %}
<option value="{{ i }}"{% if productQuantity == i %} selected{% endif %}>{{ i }}</option>
{% endfor %}
<option value="">I need more</option>
</select>
{# Error message #}
{% if entryError is defined %}
<div class="errMsg">
{{ errorList(entry.getErrors('productQuantity')) }}
</div>
{% endif %}
</form>
Form submits if title quantity is defined and if not I get entryError
defined but don't get the title's quantity's error shown.
The warning of title's quantity's error is logged in the Application Log.
Have anyone came accross this unlikely issue?
CORRECTION UPDATE
Thanks to the Robin's comment bellow to debug it with {{ dump() }}
function I found out that input quantity field with variable is returning the error value. title
However I didn't mentioned in my question that I'm actually posting/retrieving to/from matrix field as I didn't want to make the question pointlessly complicated with all those fields I've set.
I've been misleaded/figured that to access field's variable in
{{ errorList(entry.getErrors('variable')) }}
for example, is not valid for matrix field.
Now I can't find any info on how to access matrix field for entry validation using:
{% macro errorList(errors) %}{% endmacro %}
.
entryError
and especiallyentryError.getErrors()
is it your entry and does the array contain the errors? By the way your form is missing its type idid
. Anyway, check the question update. You've got me on right track. Here is what I got for title:array(2) { ["title"]=> array(1) { [0]=> string(22) "Title cannot be blank." }
and here is what I've got for matrix field accessed just by matrix fieldhandle
:["event"]=> array(1) { [0]=> string(32) "Correct the errors listed above." } }
.