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 /

FormAction in CMS ignores its $action




Community Member, 4 Posts

24 December 2009 at 5:20am

Good day, people.

I need your help. I've got the nessecarity of adding an ActionForm into the CMS pages which will send emails to all who subscribed on that pages. By this i've found - there is an detail instruction how to add ActionForm into CMS. I've adapted it for my task and i'd say that it works perfectly if there won't be a trouble - when i send a form it looks like there's no $action for it. Iframe just refreshes without sending any data. While debuggin i tried director::redirect(MySitedomain) in $action function - if there is an $action i must see my site in form frame after sending form data but it fails (the same trick works in function which returns the form).
I also put my source code on site pages (with nessecary changes in getting pages IDs) and it works. But not in CMS.

My code is below:


class EventPage extends Page{

   public function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Subscribers", new LiteralField('iframe','<iframe src="/MailController/iframe/'.$this->ID.'" width="100%" height="200"></iframe>'));

      return $fields;


class MailController extends Controller{
   static $allowed_actions = array ('iframe', 'sendmail', 'MailForm');
   function MailForm(){
      $params = Director::urlParams();
      $fields = new FieldSet();
      $fields->push(new TextareaField("Letter", "Letter to subscribers",5,50));
      $fields->push(new HiddenField('ID', 'Page ID',$params['ID']));
      $actions = new FormAction("sendmail", "Send mail to subscribers");
      return new Form($this, "MailForm", $fields, $actions);

   function sendmail($data, $form){
      $sqlQuery = new SQLQuery();
      $sqlQuery->select = array('MemberID');
      $sqlQuery->from = array("EventPage_Members");
      $sqlQuery->where = array("EventPageID=".$data[ID]);
      $rawSQL = $sqlQuery->sql();
      $result = $sqlQuery->execute();
      foreach($result as $row){
         $query .= $row[MemberID]." OR ID=";
      $query .= $row[MemberID];
      $memberList = DataObject::get("Member", $query,"","","");
      foreach ($memberList as $member){         
            $email = new Email_Template();
            $email->from = "**";
            $email->subject = "**";
            $email->to = $member->Email;
            $email->body = $data[Letter];
            $email->ss_template = 'SubscribeTemplate';
   function Link(){

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

Waiting for your help :-)