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:

Form Questions /

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

Can't insert dynamic value into HiddenField


Go to End


1000 Views

Avatar
_Matt

Community Member, 29 Posts

28 April 2013 at 1:40am

I'm trying to automatically insert a dynamic value into a HiddenField, but I can't get it working. At the moment I just get 'value="0"'.

This is a simplified version of what I'm trying to do:

static $db = array(
    'MyID' => 'Int'
);

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $myID = 9999; // In my code this value is set dynamically

    return new FieldList(
        new HiddenField('MyID', 'My ID', $myID)
    );
}

My dynamic value definitely works as I'm able to var_dump() it.

Can anyone explain why this doesn't work?