Jump to:

23456 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » How does page/action/ID construct work

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

Page: 1
Go to End
Author Topic: 1401 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    How does page/action/ID construct work Link to this post

    I'm trying to figure out how the page/action/ID construct works, but the documentation page doesn't exist.

    I have a Product Review form in my Product_Controller. In the template the Form Gets automagically Hidden and Revealed with jQuery. However when I add the reCaptcha plug-in all hell breaks loose. I figure the problem is the AJAX call in reCaptcha doesn't like to be called into a HIdden div. So I thought why don't I make the form generation an AJAX call.

    Reading the AJAX intro in the REcipes section I understand I need to call DataObjects as pages, and tell the page controller to use a differnrt tempalte for AJAX calls. But I can't get the form to Render in its own Page.

    Here is the Form Function if it Helps

    class Product_Controller extends Page_Controller {
       
       /**
        * Include the product group's requirements, override if the project has the file,
        * otherwise use the module one instead
        */   
       function init(){
          Requirements::javascript('jsparty/prototype.js');
          Requirements::javascript('jsparty/prototype_improvements.js');
          Requirements::javascript('jsparty/behaviour.js');
          Requirements::javascript('ecommerce/javascript/Product.js');
          
          //Requirements::themedCSS('Product');

          parent::init();
       }
       
       
       /**Create Review Form****
       ************************
       ************************/
       function UserProductReviewForm() {
    // Create fields
        $recaptchaField = new RecaptchaField('MyCaptcha');
        $recaptchaField->jsOptions = array('theme' => 'white');
       
    $fields = new FieldSet(
                          new TextField('Name','Name:'),
                          new EmailField('Email','E-Mail Address:'),
                          new TextField('Location','Location:'),
                          new OptionsetField('Rating','Rating',array(
                                                          '1' => '1',
                                                          '2' => '2',
                                                          '3' => '3',
                                                          '4' => '4',
                                                          '5' => '5',
                                                          )
                                        ),
                          new TextField('Title','Review Title:'),
                          new TextareaField('Review'),
                          //$recaptchaField,
                          new HiddenField('ProductID', '', $this->ID),
                          new HiddenField('ProductName','',$this->Title)
    );
    // Create actions
    $actions = new FieldSet(
    new FormAction('doReview', 'Submit')
    );

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

    }

    function doReview($data, $form) {
    $review = new Review();
    $form->saveInto($review);
    $review->write();
    }   
    }

    I've commented out the offending reCaptcha element. Shouldn't I be able to load the form with

    mysite.com/product-name/UserProductReviewForm

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: How does page/action/ID construct work Link to this post

    Shouldn't I be able to load the form with mysite.com/product-name/UserProductReviewForm

    No as UserProductReviewForm returns a Form Object. You would include $UserProductReviewForm in the main product name page to load the form or make your own action which just returns an array

    function addreview() {
    return array(
    'Title'=> "Add Review",
    'Form' => $this->UserProductReviewForm()
    );
    }

    Then you would go mysite.com/product-name/addreview and have the ability to have a ProductPage_addreview.ss template which has the $Form var to load your form.

    Documentation is a bit light on this but its started.

    http://doc.silverstripe.com/doku.php?id=execution-pipeline
    http://doc.silverstripe.com/doku.php?id=director

    1401 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.