Tady zasílám zdrojáky kódů, s posíláním mailů.
PageController:
public function contactAction() {
$enquiry = new Enquiry();
$form = $this->createForm(new EnquiryType(), $enquiry);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bind($request);
if ($form->isValid()) {
$attachment = Swift_Attachment::fromPath($enquiry->getFile(), 'image/jpeg')
->setFilename('vylanyfoto.jpg');
$message = \Swift_Message::newInstance()
->setSubject('Další nakalený foto z webu')
->setFrom('partymanx@seznam.cz')
->setTo($this->container->getParameter('fotopriznani.emails.contact_email'))
->setBody($this->renderView('FotoPriznaniBundle:Page:contactEmail.txt.twig', array('enquiry' => $enquiry)))
->attach($attachment);
$this->get('mailer')->send($message);
$this->get('session')->getFlashBag()->add('blogger-notice', 'Tvoje párty šlupková fotka byla úspěšně odeslána a zařadila se do fronty na publikování. Sleduj FB');
// Redirect - This is important to prevent users re-posting
// the form if they refresh the page
return $this->redirect($this->generateUrl('FotoPriznaniBundle_contact'));
}
}
return $this->render('FotoPriznaniBundle:Page:contact.html.twig', array(
'form' => $form->createView()
));
}
Contacttwig formulář:
<p>Zaslat jakoukoliv fotografii z pařby můžete zcela anonymně. Jediný povolený formát je .jpg/.jpeg</p>
<form action="{{ path('FotoPriznaniBundle_contact') }}" method="post" {{ form_enctype(form) }} class="blogger">
{{form_errors (form)}}
{{form_row (form.body)}}
{{form_row (form.file)}}
{{form_rest (form)}}
<input type = "submit" value="Odeslat"/>
</form>
contactEmail.txt.twix
A contact enquiry was made at {{ "now" | date("Y-m-d H:i") }}.
Subject: Vykalený fotopřiznání z akcí
Body:
{{ enquiry.body }}
Enquiry file:
public function getFile()
{
return $this->file;
}
public function setFile($file)
{
$dir = dirname($file);
$fulln = basename($file);
$this->file = $dir.'/'.$fulln;
// echo $this->file;
}
EnquiryType:
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('body', 'textarea', array(
'label' => 'Popis',
'required' => true
));
$builder->add('file', 'file', array(
'label' => 'Ožralá fotka',
'required' => true
));
}