A
A
Artyom Korchagin2020-11-09 03:52:08
PHP
Artyom Korchagin, 2020-11-09 03:52:08

How to pass data from form to CMS symfony?

There is a form

5fa8910a7348a877142078.jpeg

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]);
    }


and controller

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;
    }


Only the name 'Feedback '.date('dmY, H:i') gets into the CMS and to the mail.

All the data is needed: full name, Email, Text.

5fa892a4e6eab128860131.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question