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.

Form Questions /

Where do the form sends me?


Reply


2 Posts   804 Views

Avatar
Keika86

Community Member, 2 Posts

22 June 2011 at 6:53pm

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.

Avatar
Willr

Forum Moderator, 5513 Posts

25 June 2011 at 5:24pm

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.