Jump to:

11004 Posts in 2735 Topics by 1824 members

All other Modules

SilverStripe Forums » All other Modules » Create New Form

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 2783 Views
  • Zinal
    Avatar
    Community Member
    9 Posts

    Create New Form Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Create New Form Link to this post

    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.

  • Zinal
    Avatar
    Community Member
    9 Posts

    Re: Create New Form Link to this post

    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/');
    }

  • Jonn
    Avatar
    Community Member
    10 Posts

    Re: Create New Form Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Create New Form Link to this post

    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.

  • Jonn
    Avatar
    Community Member
    10 Posts

    Re: Create New Form Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Create New Form Link to this post

    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.

  • Jonn
    Avatar
    Community Member
    10 Posts

    Re: Create New Form Link to this post

    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.

    2783 Views
Page: 1 2
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.