Users can currently submit entries using a form on the front-end. How would I go about showing the current logged in user's existing entries and allow them to edit them through another front-end form?


Add another hidden input field "entryId" to your form. There's nice example code in the Docs:

You can modify the form to save existing entries by adding an “entryId” hidden input to the form:

<input type="hidden" name="entryId" value="{{ entry.id }}">
  • Yeah I saw that but I can't make sense of it. Users currently post entries using a form in jobs/new/index.html. The entry is viewed with jobs/{slug}. How would I go about passing the entryId into a form inside jobs/edit/index.html so users can view and edit changes? I'm pretty lost, sorry if this is confusing. Oct 27 '14 at 12:43
  • 1
    There are a number of ways to accomplish this. One way is to just request the same template jobs/{slug} but with a post or get variable 'edit', then test for the variable in the template and instead of the normal content, deliver a pre-populated form. Another would be to send the entry.id using post or get to the edit form, which would set the hidden field (and populate the fields). If you need an example, let us know. Oct 27 '14 at 14:09
  • I've got the form working and this is how I've done it. I've got an edit link leading to jobs/edit/{{ entry.id }} and inside my edit template I've included this in the form: <input type="hidden" name="entryId" value="{{ craft.request.getSegment(3) }}"> This is working and I can edit and save an entry, however prepopulating the form with {%- if entry is defined %} value="{{ entry.title }}"{% endif -%} doesn't work at all. Any idea why? Oct 27 '14 at 15:13
  • 1
    @Jamie because the template is not set in the section settings, you don't get a var entry pre-populated. So you have to set it yourself: {% set entry = craft.entries.id(craft.request.getSegment(3)).first() %} or better, set a var id first: {% set id = craft.request.getSegment(3) %} and then get the entry model with {% set entry = craft.entries.id(id).first() %}.
    – carlcs
    Oct 27 '14 at 15:25

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.