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.

Form Questions /

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

Can't insert dynamic value into HiddenField


Go to End


1241 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?