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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Custom Edit form - Fatal error: Call to a member function securityTokenEnabled() on a non-object


Go to End


4 Posts   1881 Views

Avatar
Mohan

Community Member, 19 Posts

29 April 2008 at 10:05am

Hi All,

I created a custom edit form, whenever I try to save the changes a fatal error is displayed
"Fatal error: Call to a member function securityTokenEnabled() on a non-object ".

Thanks,
Mohan

Avatar
Sean

Forum Moderator, 922 Posts

30 April 2008 at 5:21pm

Edited: 30/04/2008 5:21pm

Could you paste your code in here, or provide a link to view the code?

Or use Pastie - http://pastie.caboo.se/

Cheers,
Sean

Avatar
Mohan

Community Member, 19 Posts

1 May 2008 at 5:14am

Sean,
Thanks for your quick reply.
Please check the link for the code.
http://pastie.caboo.se/pastes/189380
For a particular member, the profile is getting displayed in their respective
field set. But, when I try to save the changes, I get fatal error.

I once again appreciate for your quick reply.

Thanks!!

Avatar
Sean

Forum Moderator, 922 Posts

1 May 2008 at 11:00pm

Edited: 01/05/2008 11:06pm

I would probably do checks before assuming that a certain record you're retrieving is there.

For example, you're calling $form->loadDataFrom($newappt). I do know that loadDataFrom() will probably throw an error if $newappt isn't an object, or an array.

Also, you probably need to do another check in your dosave() method. Checking if your $editappt variable has any contents after calling DataObject::get_by_id(). This means a non-object fatal error won't get shown if the ID was wrong, or there was no record found, because there's a write() method called which will ultimately fail on a non-object.

Oh, and one last thing, I would probably force an integer type on the ID after fetching it from $_GET, otherwise you might have some SQL injection possibilities arising. Just do something like $newappt = DataObject::get_one("NewAppt","`ID` = " . (int)$id).

Perhaps after these it might fix the problem. I don't want to just reply saying how you need to fix your code up, because that's not the intention, however, judging by the fact there's a non-object error, I think it may be caused by a lack of checking. But, in saying that, it could be something else completely! I'd say give it a go though, you've got nothing to lose!

Cheers,
Sean