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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Hidden field for the form with page title


Go to End


3 Posts   3307 Views

Avatar
NtM

Community Member, 39 Posts

12 November 2009 at 8:34am

Edited: 12/11/2009 8:35am

I defined the form in my page controller.

function SignUpForm() {
//$field = $this->dataFieldByName('Title');

// Create fields
$fields = new FieldSet(
//new TextField($name = "Seminar Name", $title = "Seminar Name", $value = Title),
new TextField($name = "name", $title = "Name", $value = ""),
new TextField($name = "company_name", $title = "Company Name"),
new TextField($name = "phone_number", $title = "Phone Number"),
new TextField($name = "email", $title = "Email"),
new HiddenField ($name = "Seminar_Name", $value = "???????")
);

// Create actions
$actions = new FieldSet(
new FormAction('doSignUp', 'Sing Up')
);

return new Form($this, 'SignUpForm', $fields, $actions);
}

My hidden field is supposed to have the title of the page as value.

I tried to do like this:
$field = $this->dataFieldByName('Title');
new HiddenField ($name = "Seminar_Name", $field->Title)

but it doesn't work.

Also some fields are supposed to be required. How would I do that?

thanks

Avatar
Willr

Forum Moderator, 5523 Posts

12 November 2009 at 9:25am

You want the page title? Then you would use $this->Title and the value is also the 3rd parameter I believe so you need to have a title

new HiddenField("Seminar_Name", "Seminar_Name", $this->Title);

For required fields see http://doc.silverstripe.org/doku.php?id=tutorial:3-forms#form_validation

Avatar
NtM

Community Member, 39 Posts

12 November 2009 at 11:52am

Edited: 12/11/2009 12:10pm

Thank you