2

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

2

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

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

| improve this answer | |
2

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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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