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.

Customising the CMS /

Ragistation form create but admin page have problem


Reply


2 Posts   1114 Views

Avatar
amarbhanu

Community Member, 57 Posts

15 June 2009 at 9:30pm

Edited: 15/06/2009 9:34pm

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....

Avatar
Willr

Forum Moderator, 5513 Posts

16 June 2009 at 5:29pm

You can view Members in the Security Section in the CMS.

If you want to get a list of Members on the site you just need to DataObject::get('Member');