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

tutorial 3


Go to End


1048 Views

Avatar
slavelabourer

Community Member, 26 Posts

29 April 2009 at 4:49pm

Hi guys,

Just having some problems getting the validation function to work on tut 3. basicallt i hit submit and the please fill out "" message doesnt appear it just reloads the page. here's the code

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $icon = "themes/tutorial/images/treeicons/home";
static $db = array(
);
static $has_one = array(
);

}

class HomePage_Controller extends Page_Controller {

function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

function doBrowserPoll($data, $form) {
$submission = new BrowserPollSubmission();
$form->saveInto($submission);
$submission->write();

Director::redirectBack();
}

function BrowserPollForm() {
// Create fields
$fields = new FieldSet(
new TextField('Name'),
new OptionsetField('Browser', 'Your Favourite Browser', array(
'Firefox' => 'Firefox',
'Internet Explorer' => 'Internet Explorer',
'Safari' => 'Safari',
'Opera' => 'Opera',
'Lynx' => 'Lynx'
))
);

// Create actions
$actions = new FieldSet(
new FormAction('doBrowserPoll', 'Submit')
);

return new Form($this, 'BrowserPollForm', $fields, $actions);
// Create validator
$validator = new RequiredFields('Name', 'Browser');

return new Form($this, 'BrowserPollForm', $fields, $actions, $validator);

}

}
?>

thanks for your help