Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Where do the form sends me?

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

Page: 1
Go to End
Author Topic: 774 Views
  • Keika86
    Avatar
    Community Member
    2 Posts

    Where do the form sends me? Link to this post

    Hi guys,

    i've been blocked by a form problem for the past 2hours.

    So in Page.php i have

       public function updateModerated() {
          //Getting URI and diving it
          $URI = explode("/", trim($_SERVER['REQUEST_URI'], "/ ")) ;
          
          //Get the URLsegment 4 on local, 3 online
          $URL = $URI[4] ;
          
          
          $query = new SQLQuery();
          $query->select("ID, isModerated, URLSegment");
          $query->from("communitymember");
          $query->where("URLSegment = '".$URL."'");
          $query->orderby("ID ASC") ;
          $query->limit(1) ;
          
          
          if($result = $query->execute()){
          
             $record = $result->current() ;
             
             if($record['isModerated'] == 1){
                         
                $fields = new FieldSet(
                   new CheckboxField("isModerated", "Moderated Profile. Uncheck this after you have reviewed the profile and consider it suitable.", 1)
                );
                
             }
             else{
                      
                $fields = new FieldSet(
                   new CheckboxField("isModerated", "Moderated Profile. Uncheck this after you have reviewed the profile and consider it suitable.")
                );
                
             }
             
          }
          else{
          
             $fields = new FieldSet(
                new CheckboxField("isModerated", "Moderated Profile. Uncheck this after you have reviewed the profile and consider it suitable.")
             );
          
          }
       
          
          $actions = new FieldSet(new FormAction("updateModeratedDB", "Save"));
          
          return new Form($this, "updateModerated", $fields, $actions);
       
       }
       
       public function updateModeratedDB(){
       
          //Getting URI and diving it
          $URI = explode("/", trim($_SERVER['REQUEST_URI'], "/ ")) ;
          
          //Get the URLsegment 4 on local, 3 online
          $URL = $URI[4] ;
          
          $query = new SQLQuery();
          $query->sql = ("UPDATE communitymember SET isModerated = ".$_POST['isModerated']." WHERE URLSegment = ".$URL);
          
          $query->execute() ;
          
          Director::RedirectBack();
       
       }

    and in my Sidebar.ss i have $updateModerated.

    The page displays the form ok. now when I click Save, nothing happens and I'm being redirected to the homepage.

    Any ideas?

    Thanks

    K.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Where do the form sends me? Link to this post

    From what you have setup it looks like it wants to send you to the updateModeratedDB() function on that controller (under the form action) however it won't ever get to that function as you're missing the 2 parameters in that method. It should be like

    function updateModeratedDB($data, $form) { ..

    You should also include 'updateModeratedDB' in your Page_Controller's $allowed_actions array().

    Also make sure that updateModerated function is in your controller class, not your model record.

    774 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.