Jump to:

10844 Posts in 2515 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Images uploaded from MultipleImageUploadField as e-mail attatchment

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 383 Views
  • Xazen
    Avatar
    Community Member
    18 Posts

    Images uploaded from MultipleImageUploadField as e-mail attatchment Link to this post

    Hello,

    I've got a simple form with MultipleImageUploadField for the frontend.

    function Form(){
          $fields = new FieldSet(
             new TextareaField('About', htmlentities('Über dich')."<span class=\"require\">*</span>", 8),
             $images = new MultipleImageUploadField('Pics', 'Bilder (Bitte Name in der Datei angeben)', array (
                'sizeLimit' => '2097152',
                'buttonText' => 'Durchsuchen..',
                'queueSizeLimit' => '5',
                'auto' => false,
                'upload_on_submit' => true
                )
             )
          );
          
          $images->imagesOnly();
          $images->uploadOnSubmit();
          $images->setUploadFolder("application");
          
          $actions = new FieldSet(
             new FormAction('doSubmitApplication','Bewerben')
          );
          $validator = new RequiredFields(
             'About'
          );
          $form = new Form(
             $this,
             'Form',
             $fields,
             $actions,
             $validator
          );
          return $form;
       }

       function doSubmitApplication($data, $form){
          $application = new Application();
          $form->saveInto($application);
          $application->write();
          Director::redirectBack();
          return;
       }

    The uploaded images should be attatched to a mail. I send the mail in the Application class in the function onBeforeWrite(). In the function I use this function.

    protected function sendEmail(){
          $body = "
             <p>{$this->About}</p>
          ";
          
          $from = Email::getAdminEmail();
          $email = new Email(
             $from,
             'test@gmx.de',
             "Application",
             $body
          );
          $email->send();
       }

    How can I get attatch the images from the Application class?

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