I have a plugin that is listening for a form submit.
Within that form are two fields firstName
and agreeToTerms
.
When the form is submitted, I am updating an existing entry with the values that were posted.
I can get all fields to update except my checkbox. I'm not sure what I need to send to craft if the user has checked the checkbox.
Here is what I have so far:
MyController
$postDateTime = ...
...
$entry->setContentFromPost(array(
'agreeToTerms' => craft()->request->getPost('fields.agreeToTerms'),
'firstName' => craft()->request->getPost('fields.electronicSignature'),
'signatureDate' => $postDateTime
));
...
This returns "1" which is the value of the checkbox.
craft()->request->getPost('fields.agreeToTerms') // returns 1
But that isn't what I need to send to Craft. If I were using jquery, I am looking for something like
$.prop('checked', true);
EDIT
To help clarify in case someone else comes across this thread, as @carlcs stated I was in fact talking about a checkbox field.
The plugin I am using allows users to create entries in a section. When an entry is created, one of the fields is a checkbox. I was attempting to set the checkbox field as checked if the user had checked the corresponding checkbox when the entry was created.