Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Useforms - trouble adding checkbox field


Go to End


5 Posts   1209 Views

Avatar
Vickula

Community Member, 5 Posts

8 January 2015 at 12:04am

Hi I'm a newbie to Silverstripe and have limited php knowledge

I've taken over a clients website from a previous developer who had set up a custom userform with a payment facility to accept payment for event registration. This works fine with the default settings but if the client want to add a checkbox of options (e.g. how did you find out about us etc) I get a server error.

The following code I'm assuming refers to the default fields that work.

static $defaultFields = array(
array('Type'=>'Text','Title'=>'Title'),
array('Type'=>'Text','Title'=>'First Name'),
array('Type'=>'Text','Title'=>'Last Name'),
array('Type'=>'Text','Title'=>'Address1'),
array('Type'=>'Text','Title'=>'Address2'),
array('Type'=>'Text','Title'=>'City'),
array('Type'=>'Text','Title'=>'County'),
array('Type'=>'Text','Title'=>'Postcode'),
array('Type'=>'Text','Title'=>'Daytime Telephone'),
array('Type'=>'Text','Title'=>'Mobile Telephone'),
array('Type'=>'Email','Title'=>'Email Address')
);

I'm thinking if I add a Checkbox array to this it would work?

Problem is I don't know the correct syntax to add - any help would be gratefully received.

Thanks

Avatar
martimiz

Forum Moderator, 1391 Posts

8 January 2015 at 1:35am

I assume that you are referring to custom code, written by the previous developer, and not the SilverStripe User Defined Forms module? Or is it some other existing module do you think? (In which director does the code live)

it's hard to tell what's going on based on this bit of code and no real error information, it probably depends on how your developer has implemented this.

First of all you might try to temporary place your site into dev mode. Place this line of code to the bottom of your /mysite/_config.php file (don't forget to remove or set to 'live' later):

Director::set_environment_type("dev");

This may get you a more detailed error message.

Then we would probably need the whole code, unless it is an existing module...

Avatar
Vickula

Community Member, 5 Posts

8 January 2015 at 2:02am

Hi martimiz

Yes I was referring to the custom code which the previous developer has customised from the Userforms module.

I added the line of code you supplied and below is the error that was thrown up.

I think what is happening is the previous developer has written the code just to include a specific array of fields as per below. But now the client wants to add the Editable Multiple Options field which is not include in the array in the custom code so therefore it is throwing up the server error!

[User Error] Please implement getFormField() on EditableMultipleOptionField
GET /get-involved/events/starwalk-2015/register-now/

Line 143 in /var/www/vhosts/domain.com/httpdocs/userforms/code/model/formfields/EditableMultipleOptionField.php
Source

134 return true;
135 }
136
137 /**
138 * Return the form field for this object in the front end form view
139 *
140 * @return FormField
141 */
142 public function getFormField() {
143 return user_error('Please implement getFormField() on '. $this->class, E_USER_ERROR);
144 }
145 }

Trace

Please implement getFormField() on EditableMultipleOptionField
EditableMultipleOptionField.php:143
EditableMultipleOptionField->getFormField()
UserDefinedForm.php:514
UserDefinedForm_Controller->getFormFields()
UserDefinedForm.php:478
UserDefinedForm_Controller->Form()
UserDefinedForm.php:445
UserDefinedForm_Controller->index(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,index)
Controller.php:194
Controller->handleAction(SS_HTTPRequest,index)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:202
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:185
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:185
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:185
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:78
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:366
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:152
Director::direct(/get-involved/events/starwalk-2015/register-now/,DataModel)
main.php:189

Avatar
martimiz

Forum Moderator, 1391 Posts

8 January 2015 at 3:39am

Edited: 08/01/2015 3:42am

I don't know in what way exactly your your developer adapted the UserForms module, but normally you would define your formfields from within the CMS, and the only options you have for a a multi-option field is either:

- Checkbox group (EditableCheckboxGroupField)
- Dropdown field (EditableDropdownField)

It looks like your client is trying to create a EditableMultipleOptionField. This is not actually a formfield, but should be seen as an abstract class, and it is used as a base (parent) class for multi-option fields like the two above. If you try to use it as a FormField on its own, it will give the rather cryptical error 'Please implement getFormField() on EditableMultipleOptionField'. So I'd suggest using one of the two above.

I cannot quite understand though, how your client is able to construct an EditableMultipleOptionField like that. Are they not using the Form settings from within the CMS? (EDIT: probably not, concidering the array you posted :))

Avatar
Vickula

Community Member, 5 Posts

8 January 2015 at 4:05am

That did the trick - thanks!
Don't know why the other options are showing in the CMS or why the client chose to use that rather than the checkbox!