Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send data from form to controller
    primarykey
    data
    text
    <p>In my web store, built on OpenCart, I've created absolutely new template and controller for it. Path is template/common/orderForm. In this template there is a very simple contact form.</p> <p>Template code (not very much, I didn't even include the header).</p> <pre><code>&lt;!doctype html&gt; &lt;div style="width: 723px;"&gt; &lt;form action="&lt;?php echo $action; ?&gt;" method="post"&gt; Ваше имя: &lt;input type="text" name="your_name"&gt;&lt;br&gt; Ваше e-mail: &lt;input type="text" name="email"&gt;&lt;br&gt; &lt;input type="submit" value="Заказать"&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Well, the biggest problem is that I don't know how to send data from form to controller. All I need to understand is how to do that. The other part, like sending form data via email, I can handle myself. Honestly, I totally can't understand OpenCart system.</p> <p>Controller code</p> <pre><code>&lt;?php class ControllerCommonOrderForm extends Controller { public function index() { $this-&gt;document-&gt;setTitle($this-&gt;config-&gt;get('config_title')); $this-&gt;document-&gt;setDescription($this-&gt;config-&gt;get('config_meta_description')); $this-&gt;data['action'] = $this-&gt;url-&gt;link('common/orderForm'); $this-&gt;data['heading_title'] = $this-&gt;config-&gt;get('config_title'); if (file_exists(DIR_TEMPLATE . $this-&gt;config-&gt;get('config_template') . '/template/common/orderForm.tpl')) { $this-&gt;template = $this-&gt;config-&gt;get('config_template') . '/template/common/orderForm.tpl'; } else { $this-&gt;template = 'default/template/common/orderForm.tpl'; } $this-&gt;children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this-&gt;response-&gt;setOutput($this-&gt;render()); /* Input data check */ $your_name = $this-&gt;config-&gt;get('your_name'); echo $your_name; $email = htmlspecialchars($_POST["email"]); /* Устанавливаем e-mail адресата */ $myemail = "the.eolithic@gmail.com"; /* Создаем новую переменную, присвоив ей значение */ $message_to_myemail = "Здравствуйте! Вашей контактной формой было отправлено сообщение! Имя отправителя: $your_name E-mail: $email Конец"; /* Отправляем сообщение, используя mail() функцию */ $from = "From: $yourname &lt;$email&gt; \r\n Reply-To: $email \r\n"; mail($myemail, $message_to_myemail, $from); ?&gt; &lt;p&gt;Ваше сообщение было успешно отправлено!&lt;/p&gt; &lt;p&gt;На &lt;a href="index.php"&gt;Главную &gt;&gt;&gt;&lt;/a&gt;&lt;/p&gt; &lt;?php /* Если при заполнении формы были допущены ошибки сработает следующий код: */ function check_input($data, $problem = "") { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem &amp;&amp; strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?&gt; &lt;html&gt; &lt;body&gt; &lt;p&gt;Пожалуйста исправьте следующую ошибку:&lt;/p&gt; &lt;?php echo $myError; ?&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php exit(); } } } ?&gt; </code></pre> <p>Everytime I go to the form page, I get these errors. And I don't even press the submit button.</p> <pre><code>Notice: Undefined variable: yourname in C:\apache\localhost\www\webshop.kg\catalog\controller\common\orderForm.php on line 40Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\apache\localhost\www\webshop.kg\catalog\controller\common\orderForm.php on line 41 </code></pre> <p>Thank you for your attention. I hope you know how to resolve my problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload