Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

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

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

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

Page: 1
Go to End
Author Topic: 1567 Views
  • Mohan
    Avatar
    Community Member
    19 Posts

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

    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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

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

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

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

    Cheers,
    Sean

  • Mohan
    Avatar
    Community Member
    19 Posts

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

    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!!

  • Sean
    Avatar
    Forum Moderator
    921 Posts

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

    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

    1567 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.