Answer the question
In order to leave comments, you need to log in
How to pass data from form to CMS symfony?
There is a form
Data is processed by Symfony code
public function actFeedbackForm()
{
$post = $this->request->request;
$array = $post->all();
// if (empty($array['email']) or empty($array['username']) or empty($array['phone']) or empty($array['text'])) {
// return json_encode(['status' => 'error']);
// }
$id = $this->models['feedback']->save($post);
// $email = $this->models['orm']->getObject(5, true);
$host = $this->request->server->get('HTTP_HOST');
$this->mailer->setTo('[email protected]');
$this->mailer->setSubject('Заявка №'.$id.', '.$array['username']);
$this->mailer->setContent('<html>'
.'Здравствуйте <b>Администратор</b>!<br />'
.'Только что пользователь сайта <a href="http://'.$host.'" target="_blank">'.$host.'</a> отправил сообщение с формы обратной связи.<br /><br />'
.'Email: <b>'.$array['email'].'</b><br />'
.'Имя: <b>'.$array['username'].'</b><br />'
.'Телефон: <b>'.$array['phone'].'</b><br />'
.( !empty($array['project']) ? '<b>Проект</b>: '.$array['project'].'<br>' : '')
.'<b>Текст сообщения:</b><br />'
.(isset($array['text']) ? $array['text'].'<br>' : '')
.'<br />'
.'<br />'
.'С уважением, система сайта <a href="http://'.$host.'" target="_blank">'.$host.'</a>'
.'</html>');
$this->mailer->send();
return json_encode(['id' => $id]);
}
final public function save($data)
{
$array = $data->all();
$array['name'] = 'Обратная связь '.date('d.m.Y, H:i');
$array['class_id'] = 39;
$array['parent_id'] = 820;
$id = $this->addObject($array, $array);
return $id;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question