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

Populating Hidden Field Value with Value Entered in CMS


Go to End


3374 Views

Avatar
geisha64

Community Member, 5 Posts

14 February 2009 at 12:38pm

I have created a custom field called retURL for the user to enter a URL in the CMS. I want to access this value in the Custom form hidden field.

I have tried the following and get the value "Array" back:
new HiddenField("retURL","retURL",DataObject::get('RegistrationForm')->column('retURL')),

Can someone point me in the right direction on how to access the retURL value for the specific page that is created off of this RegistrationForm page type?

CODE:
<?php
class RegistrationForm extends Page {

static $db = array(
'retURL' => 'Varchar(255)'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('retURL','Page URL'), 'Content');
return $fields;
}

} //class RegistrationForm

class extForm extends Form {
function init() {
parent::init();
}
.....
}

class RegistrationForm_Controller extends Page_Controller {

function Form() {
return new extForm($this, "Form", new FieldSet(

// List your fields here
new TextField("first_name", "First Name"),
new TextField("last_name","Last Name"),
new HiddenField("retURL","retURL",DataObject::get('RegistrationForm')->column('retURL')),

), new FieldSet(

// List the action buttons here
new FormAction("", "Sign up")

), new RequiredFields(

// List the required fields here: "Email", "FirstName"
"first_name","last_name"
));
}

..........