2

I'm going wrong here somewhere, but I have a (edit) entry form and I'd like a 'disable' field to change status. The edit form works fine but status changes are ignored. Here's my field:

<input type="checkbox" name="enabled" id="enabled" value="{{ entry.enabled }}"{{ entry.enabled == '1' ? ' checked' }}>

Am I missing something? Thanks guys.

4

You need to include a hidden field with the value of 0 before the checkbox to ensure that the value is included in the form data if the checkbox is unchecked. See the docs on templating for checkbox fields.

So you'll need to have this in your form:

<input type="hidden" name="enabled" value="0">
<input type="checkbox" name="enabled" id="enabled" value="1"{{ entry.enabled == '1' ? ' checked' }}>

When the checkbox is checked, the value of 1 for enabled will override the value of the earlier hidden field.

  • Thanks Steve. Did not know that. Alas, it hasn't solved the problem. – Ian Ebden Jul 27 '16 at 10:45
  • Hmm. It's working for me. What's the problem? Don't forget that to show disabled entries on the front end you'll need to add a status(null) criteria to the craft.entries tag. Also, does the user your trying to do this with have appropriate permissions for the section your entries are in? – Steve Rowling Jul 27 '16 at 10:55
  • Yep, that all checks out but no dice. I'm going to have to dig a little deeper. I'll post the answer once I have it. – Ian Ebden Jul 27 '16 at 11:24
  • Seems I can disable fine but cannot enable again after, which suggests to me it's some kind of permissions thing. Yet I'm logged in as Admin with full rights. Tried different sections too. – Ian Ebden Jul 27 '16 at 12:11
  • Have you got dev mode on and looked in the logs to see if there is anything helpful in there? Does the entry save, but remain disabled? Or does it fail to save any changes? I've double-checked here and it's working for me when logged in as an Admin so it does sound like there is perhaps a permissions issue or something else preventing it working for you. – Steve Rowling Jul 27 '16 at 14:43

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.