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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

How does page/action/ID construct work


Go to End


2 Posts   1811 Views

Avatar
zenmonkey

Community Member, 545 Posts

5 September 2009 at 2:00am

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

Avatar
Willr

Forum Moderator, 5523 Posts

5 September 2009 at 11:40am

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