i used help for coding
http://doc.silverstripe.org/doku.php?id=recipes:forms
and code is :
<?php
class RegistrationForm extends Page {
}
class RegistrationForm_Controller extends Page_Controller {
private $defaultGroupID = 2;
/**
* This function lets you put a form on your page, using $Form.
*/
function Form() {
return new Form($this, "Form", new FieldSet(
// List your fields here
new TextField("FirstName", "First name"),
new TextField("Surname"),
new EmailField("Email", "Email address")
), new FieldSet(
// List the action buttons here
new FormAction("SignupAction", "Sign up")
), new RequiredFields(
// List the required fields here: "Email", "FirstName"
));
}
/**
* This function is called when the user submits the form.
*/
function SignupAction($data, $form) {
// Create a new Member object and load the form data into it
$member = new Member();
$form->saveInto($member);
// Write it to the database. This needs to happen before we add it to a group
$member->write();
// Add the member to group. (Check if it exists first)
if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) {
$member->Groups()->add($group);
// Redirect to a page thanking people for registering
Director::redirect('thanks-for-registering/');
}else{
// Redirect to a failure page
Director::redirect('registration-failed/');
}
}
}
?>
i have two problem:
1. dropdown list create problem.
2. data base have data but how to access this data.
i haven't any idea so please help me and send some help of links and suggestion please send....