How to create duplicate for default opencart contact us form with additional fields

StackOverflow https://stackoverflow.com/questions/22810368

  •  26-06-2023
  •  | 
  •  

Question

In my opencart template i need to create a form which is similar to contact form with the fields Name,Email and Mobile number.I have already used the default contact us form in my contact us page.I need to create this new form for another page.Is there any free extension available?Or else how can we implement our own form?

Was it helpful?

Solution

I am not going to recommend any extension (this is not the place to do so) but i can tell you some steps duplicate the contact from.

First you need to duplicate three files in their respective directories

  1. catalog\language\english\information\contact.php
  2. catalog\view\theme\default\template\information\contact.tpl
  3. catalog\controller\information\contact.php

and name them form.php,form.tpl,form.php

All changes after this point will be performed on these files only

now change you controller class name to ControllerInformationForm other than this you will have to edit several things in controller file like change contact.tpl to form.tpl , load correct language file using $this->language->load('information/form');

after making necessary changes to controller file, your new form can be accessed using website.com/index.php?route=information/form

now for additional field take one existing field like name and do all things which are done for name in these 3 files with your new field

Note don't do $mail->setSender($this->request->post['name']); for you new field its different

now lets in tpl you have new field in tpl like this

<input type="text" name="city" value="<?php echo $city; ?>" />

then in your controller change following line

$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));

to

$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'] . " " . $this->request->post['city'], ENT_QUOTES, 'UTF-8')));

Disclaimer : This not a full set of instruction but this is enough for you to start and to ask better question if you face any problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top