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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Create New Form


Go to End


10 Posts   4377 Views

Avatar
Zinal

Community Member, 9 Posts

1 January 2011 at 1:13am

Edited: 01/01/2011 1:22am

hi all,
Happy new year

I have created new form and form is created successfully but i have shown below error for clicking on submit button.

[User Warning] popCurrent called on ModelAsController controller, but it wasn't at the top of the stack

Source

445 }
446
447 /**
448 * Pop this controller off the top of the stack.
449 */
450 function popCurrent() {
451 if($this === self::$controller_stack[0]) {
452 array_shift(self::$controller_stack);
453 } else {
454 user_error("popCurrent called on $this->class controller, but it wasn't at the top of the stack", E_USER_WARNING);
455 }
456 }
457
458 /**
459 * Redirct to the given URL.
460 * It is generally recommended to call Director::redirect() rather than calling this function directly.

Trace

* popCurrent called on ModelAsController controller, but it wasn't at the top of the stack
Line 454 of Controller.php
* Controller->popCurrent()
Line 76 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 283 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 127 of Director.php
* Director::direct(sports/outdoor-sports/event/dead-sea-ultra-marathon/23/ReviewForm)
Line 130 of main.php
* require_once(D:\htdocs\testing\sapphire\main.php)
Line 63 of index.php

if anyone know why this error occurs and how it is solved then please tell me.

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

1 January 2011 at 6:09pm

Could you provide some more information such as version numbers of your SS installation and what version of forms you are using. Also try refreshing the CMS.

Avatar
Zinal

Community Member, 9 Posts

3 January 2011 at 9:24pm

Edited: 03/01/2011 9:25pm

hi...

Thanks for reply. I am using Silverstripe 2.4.0...
I have added code for creating form. please help me how can i solve this error?

Code:
public function ReviewForm($params = null)
{
return new Form($this, "ReviewForm", new FieldSet(

// List your fields here
new TextField("Name", "Full Name"),
new TextField("ReviewRating","Review Rating"),
new TextField("ReviewTitle", "Review Title"),
new TextareaField("ReviewDescription", "Review Description")

), new FieldSet(

// List the action buttons here
new FormAction("ReviewFormAction", "Submit")

), new RequiredFields("Name","ReviewRating","ReviewTitle","ReviewDescription"

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

));
}

public function ReviewFormAction($data, $form)
{
$reviews = new EventReview();
$form->saveInto($reviews);
$reviews->write();
Director::redirect('thanks/');
}

Avatar
Jonn

Community Member, 10 Posts

7 January 2011 at 4:25pm

Edited: 07/01/2011 4:26pm

Hi,

I am getting the same error on my forms, is your form on a page generated from a data object?

For Example:

class Product extends DataObject
{
...

Form Code Here
}

I'm guessing it's because the code is being called in a DataObject rather than a controller but I'm not sure how to resolve the error.

Avatar
Willr

Forum Moderator, 5523 Posts

7 January 2011 at 7:11pm

John: you can get the latest controller using Controller::curr(); usually this is a safe bet if for some reason you cannot get direct access to the controller i.e $this. Normally I store fields, required fields on the model then build the form on the controller. Or a better way to get around it is to make your own subclass of form as explained on http://doc.silverstripe.org/form#by_subclassing.

Avatar
Jonn

Community Member, 10 Posts

10 January 2011 at 12:56pm

Edited: 10/01/2011 12:57pm

Hi Willr,

Thanks for the quick reply.

As per your suggestion I moved the form into its own subclass so now I have:

class Product extends DataObject
{ 
...

   function QuoteForm(){ 
      $form = new QuoteForm($this, "QuoteForm"); 
      return $form; 
   }
}

I've also move the send email code to the subclass but I am still getting the popCurrent called on ModelAsController controller, but it wasn't at the top of the stack error.

Do I need to point a completed form back to the subclass in my QuoteForm function?

Avatar
Willr

Forum Moderator, 5523 Posts

10 January 2011 at 1:41pm

class Product extends DataObject 
{ 
...

function QuoteForm(){ 
$form = new QuoteForm($this, "QuoteForm"); 
return $form; 
} 

$this in that example is still only a dataobject. It must be a controller instance. I can't help without much more information about how you have structured it but the new QuoteForm() should be called with a controller in mind.

Avatar
Jonn

Community Member, 10 Posts

10 January 2011 at 1:54pm

Edited: 10/01/2011 2:05pm

Hi Willr,

What I am trying to do is add a request a quote form to each product page which is rendered from a data object. I followed Aram's Tutorial on SSbits to make the product functionality.

http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/

I have a category page which renders the product page.

//Get the Product
		if($Product = $this->getCurrentProduct())
		{
		    $Data = array(
		        'Product' => $Product,
				'MetaTitle' => $Product->MetaTitle,
				'MetaDescription' => $Product->MetaDescription,
				'MetaKeywords' => $Product->MetaKeywords
		    );
		     
		    //return our $Data array to use, rendering with the ProductPage.ss template
		    return $this->customise($Data)->renderWith(array('ProductPage', 'Page'));			
		}

I noticed when I used Controller::curr(); instead of $this it seemed to be trying to use the category page controller.

Go to Top