Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I am looking for some help with persistent form data.

If a user submits a front-end entry form for some Entries data, but there are errors with the submission, they are currently redirected to the entry page and successfully shown the errors (eg field is required). Is there a method or syntax where this form can also retrieve the posted form data so the user is not required to fill in the whole form again?

Many thanks for any help from the community!

Dan

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I've updated our front-end entry template example to show you how this can be done:

http://buildwithcraft.com/docs/templating/entry-form

share|improve this answer
    
Thanks Brad that is very good, and helpful. –  Dan G Aug 12 at 14:16

If there are any problems with your submission, Craft sets an entry route variable1, which you can use to retrieve the previously-posted form data.

Here's an example of how you might do that:

<input
    id="title"
    type="text"
    name="title"
    value="{{ entry is defined ? entry.title : '' }}",
>

You can also retrieve the errors from the entry variable:

{% if (entry is defined) and (entry.hasErrors('title')) %}
    <span class="error">{{ entry.getError('title') }}</span>
{% endif %}

If you want to learn more about the validation-related methods available on the entry object (such as the difference between getError and getErrors), I've written a blog post on the subject.

Stephen

  1. Take a look at line 477 of craft/app/controllers/EntriesController.php
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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