1

I have an entry form in home page which the home page already using the entry object.

And I am placing the entry form in home page when i call

{%- if entry is defined %} value="{{ entry.title }}"{% endif -%}

and this will grab the home page title, and this is not the result i want. I need when the form submit and error return with value.

By the way, any source to learn about entry form? I don't see much tutorial about entry form. Thanks.

3
  • What does the hyphen mean in the tag? This part: "{%-". As in, what's the difference between {% if %} and {%- if %} Commented Feb 3, 2015 at 20:14
  • @NathanDHuening Using hyphens in your Twig tags allows you to remove whitespace. Have a look here: twig.sensiolabs.org/doc/templates.html#whitespace-control
    – Jamie Wade
    Commented Feb 4, 2015 at 9:19
  • @JamieWade Ah.. Thanks for the explaination. Me myself also forgot this. haha
    – Hs Tung
    Commented Feb 4, 2015 at 10:03

3 Answers 3

3

If you use the Guest Entries plugin to submit the entry, then the variable that the invalid entry is called is actually configurable, using the entryVariable config setting.

So just create a new file in craft/config/ called guestentries.php, with this:

<?php

return array(
    'entryVariable' => 'invalidEntry'
);

Then from your template you can just check to see if invalidEntry is defined.

2
  • Hi brandon, what if not using guest entry but normal form? How do i change the variable like the same as guest entry? Cause my single page using "entry" and form too using "entry" as well.
    – Hs Tung
    Commented Nov 2, 2014 at 18:36
  • 1
    @HsTung Currently it’s not possible with the normal entries/saveEntry action. Commented Nov 2, 2014 at 23:06
3

It sounds like you've got your home page setup as a Single. Which is a great way to go, and that's what is automatically setting the entry variable.

Here's a great walkthrough on creating an "edit entry" form...

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

Keep in mind, that example uses entry to represent the entry being edited. That won't work for you, however, since entry is being automatically set as your home page Single.

So when you're attempting to modify another entry, I'd recommend setting it to a different variable name. Obviously you can't have your home page and other entry both be represented by a variable named entry.

{% set entryToEdit = craft.entries.slug('my-entry-to-edit').first %}

Then entryToEdit would replace any instances of entry in the documented example.

2
  • Thanks for your answer but what if that is new entry form but not edit form? I want to retain the value when there is error occur after form post. the form exactly like mention in doc http://buildwithcraft.com/docs/templating/entry-form How should I replace the entry variable in the form with something else since you mention single had use my entry variable.
    – Hs Tung
    Commented Nov 1, 2014 at 15:54
  • That's an interesting question... Typically, when you submit to entries/saveEntry (as this form is doing) it will reload the page with any error messages attached to the entry object. Those would be accessed via entry.getErrors(). But... what would it return in this case? Would there be a collision when the page is reloaded? I suspect there would be... You may want to email [email protected] to get more clarification.
    – Lindsey D
    Commented Nov 1, 2014 at 18:26
1

I got this plugin from Brandon. https://github.com/pixelandtonic/GuestEntries

And it solve the problem I face. Now I able allow guest to submit entry and it able to change the variable not to use entry but any variable you name in config.

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.