Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » FormAction in CMS ignores its $action

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

Page: 1
Go to End
Author Topic: 840 Views
  • Foldor
    Community Member
    4 Posts

    FormAction in CMS ignores its $action Link to this post

    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 http://www.silverstripe.org/customising-the-cms/show/251460 - 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    Waiting for your help


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.