Please note that the forum isn't realy used anymore.

If you have questions, want support or just simply want to talk to us you can find us on slack.

 

PDF upload field in frontend

I m looking for a way to get a PDF upload field in a frontend form. This form is not generated by the formbuilder, because it is part of a module.

  • How to get this uploadfield in the form?
  • How to mail this to the recipient with the mailer attachment.

Current form fields:

    $this->frm->addText('naam')->setAttributes(array('required' => null));
    $this->frm->addText('voornaam')->setAttributes(array('required' => null));
    $this->frm->addText('straatnr');
    $this->frm->addText('postcode');
    $this->frm->addText('gemeente');
    $this->frm->addText('nationaliteit');
    $this->frm->addText('email')->setAttributes(array('required' => null, 'type' => 'email'));  
    $this->frm->addText('telefoon');

Current working mailer code:

                $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');

                $message = \Common\Mailer\Message::newInstance($subject)
                    ->setFrom(array($email => $fullName))
                    ->setto(array($to['email'] => $to['name']))
                    ->setReplyTo(array($email => $fullName))
                    ->parseHtml(
                        FRONTEND_MODULES_PATH . '/Jobs/Layout/Templates/Mails/Apply.tpl',
                        $variables,
                        true
                    )
                ;
                $this->get('mailer')->send($message);

That indeed helps me a lot. Thx Wouter.
On a side note: is it possible to sent the file as attachment without it being uploaded to a path on the server?

I guess it should be possible by using $this->frm->getFields('file')->getTempFileName() instead of the $pathToFile variable, but I'm not 100% sure, you should test it ;)

Well i ve tested it and the following code seems to work fine. You never know this could help in a future project:

                    ->attach(
                        \Swift_Attachment::fromPath($_FILES['file']['tmp_name'])->setFilename( $item['voornaam'].' '. $item['naam'].'.'.$fileExt)
                    )

Comment

The forum is deprecated in favor of our Slack channel, which provides real-time support for your issues.

Join us on Slack here: https://fork-cms.herokuapp.com/