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.

General Questions /

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

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

redirect thanks page create Problem


Reply


2 Posts   1422 Views

Avatar
amarbhanu

Community Member, 57 Posts

17 June 2009 at 2:10am

Edited: 17/06/2009 12:30pm

when i redirect to thanks page then

msg :

Sorry, it seems you were trying to access a page that doesn't exist.

Please check the spelling of the URL you were trying to access and try again.

so, created a thanks page "http://localhost/SilverStripe-v2.3.1/thanks/" then page redirect well but problem is that i created by admin content page so this page also show when we navigate a this site so please help me without navigation show create a thanks page................

me code is :

<?php
class RegistrationForm extends Page {

}

   class MyObject extends DataObject {
    static $db = array(
      'Typeofenquiry' => "Enum('Please select,Business Development,Hall Hire,Events,Membership,Accounts,Library & Archives,General','Please select')"
    );
   }
   
class RegistrationForm_Controller extends Page_Controller {

   // Make sure you set this to the right group.
   // See http://doc.silverstripe.com/doku.php?do=show&id=recipes%3Aforms
   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("Name", "name"),
         new TextField("JobTitle","Job title"),
         new TextField("CompanyName","Company name"),
         new TextField("Address","Address"),
         new TextField("Post code","Post code"),
         new TextField("Telephone","Telephone"),
         new TextField("Mobile","Mobile"),
         new EmailField("Email", "Email"),
         new TextField("Enquiry","Enquiry"),
         new TextField("TypeOfFunction","Type of function"),
         new TextField("NumbersAttending","Numbers attending"),
         new TextField("PreferedDates","Prefered dates"),
         new DropdownField('Typeofenquiry',
          'Type of enquiry',
          singleton('MyObject')->dbObject('Typeofenquiry')->enumValues())
         

      ), new FieldSet(

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

      ), new RequiredFields(
         "Email", "Name","Enquiry","Telephone"

         // List the required fields here: "Email", "FirstName"

      ),
      $field = new DropdownField(
          'Typeofenquiry',
          'Typeofenquiry',
          singleton('MyObject')->dbObject('Typeofenquiry')->enumValues()
         )
      );
   }

   /**
   * 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/');
         //Director::redirect('http://localhost/SilverStripe-v2.3.1/thanks/');

      }else{

         // Redirect to a failure page
         Director::redirect('registration-failed/');

      }
      
      

   }
}

?>

Avatar
CHD

Community Member, 218 Posts

11 June 2011 at 4:07am

well to hide the page from navigation, you just use the checkbox under the "behaviour" tab to remove it from site search and site nav.

also, this may come in handy for anybody who wants to easily include forms in a sidebar or any other area of the site, without controlling a hidden page:

http://www.clickheredigital.co.uk/blog/how-to-include-a-silverstripe-form-on-any-every-page/

it also has an easy "query database for existing member" function that isn't covered in the form tutorials...