Post by tetla » Sat Nov 25, 2017 1:24 am

Hello,

I want to add a phone field in the contact form.

How can I do it?

Attachments

phone.jpg

phone.jpg (108.21 KiB) Viewed 2485 times


Newbie

Posts

Joined
Wed Feb 22, 2017 12:12 am

Post by straightlight » Sat Nov 25, 2017 1:58 am

Since you're using a custom theme, any URL you could provide?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by tetla » Sat Nov 25, 2017 2:13 am


Newbie

Posts

Joined
Wed Feb 22, 2017 12:12 am

Post by straightlight » Sat Nov 25, 2017 2:25 am

In catalog/controller/information/contact.php file,

find:

Code: Select all

if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
add above:

Code: Select all

if (!empty($this->request->post['phone'])) {
			if (!preg_match('/^[0-9-+]$/', $this->request->post['phone']) || strlen(trim($this->request->post['phone'])) < 10) { 
				$this->error['phone'] = $this->language->get('error_phone');
			}
		}
Then, find:

Code: Select all

if (isset($this->error['enquiry'])) {
add above:

Code: Select all

if (isset($this->error['phone'])) {
			$data['error_phone'] = $this->error['phone'];
		} else {
			$data['error_phone'] = '';
		}
In catalog/language/<your_language_code>/information/contact.php file,

at the bottom of the file, add:

Code: Select all

$_['error_phone'] = 'Please provide a valid phone number!';
In catalog/view/theme/<your_theme>/template/information/contact.tpl file,

find:

Code: Select all

<div class="form-group required">
            <label class="col-sm-2 control-label" for="input-enquiry">{{ entry_enquiry }}</label>
            <div class="col-sm-10">
              <textarea name="enquiry" rows="10" id="input-enquiry" class="form-control">{{ enquiry }}</textarea>
              {% if error_enquiry %}
              <div class="text-danger">{{ error_enquiry }}</div>
              {% endif %}
            </div>
          </div>
add below:

Code: Select all

<div class="form-group required">
            <label class="col-sm-2 control-label" for="input-phone">{{ entry_phone }}</label>
            <div class="col-sm-10">
              <textarea name="phone" rows="10" id="input-phone" class="form-control">{{ phone }}</textarea>
              {% if error_phone %}
              <div class="text-danger">{{ error_phone }}</div>
              {% endif %}
            </div>
          </div>
Clear all caches from the admin. This should clarify the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by tetla » Sat Nov 25, 2017 3:41 am

Do the steps you told me.

but when I do a test when filling out the form fields I get an error.

for what is this?

Attachments

form.jpg

form.jpg (111.9 KiB) Viewed 2451 times


Newbie

Posts

Joined
Wed Feb 22, 2017 12:12 am

Post by straightlight » Sat Nov 25, 2017 4:11 am

You are posting your request in the v3.x releases of Opencart and your error message mentions a TPL file.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by IP_CAM » Sun Nov 26, 2017 11:17 am

Well, the above mentioned Solution will not function, as long as OC v.3 Code is
part of a contact.tpl file:
catalog/view/theme/<your_theme>/template/information/contact.tpl file

Code: Select all

<{% if error_enquiry %}
<div class="text-danger">{{ error_enquiry }}</div>
---
But it can be done, and probably easier, by use of an Extension like this:
Phone in Form free, OC v.2.0.0.0 - 2.1.0.2:
https://www.opencart.com/index.php?rout ... n_id=27735
it possibly just has to be rewritten a little, to make it work in later OC-2 Versions as well. Just try it! ;)
---
Another Solution for such:
X-Form paid, OC v.2.0.x - 3.0.2.x:
https://www.opencart.com/index.php?rout ... n_id=23081
found here:
https://www.opencart.com/index.php?rout ... earch=Form
---
For OC v.1.5.6.x, a nice free Extension exists, to keep User-Contact-Infos in the Admin Section,
but it requires additional Code in several Front Side and Back Side Pages, to make the Phone
Number work, as shown on the image below. Just to mention this ... ::)
Ernie

---
Opencart Contact form to DB free, OC v.1.5.x - 1.5.6.5_rc:
https://www.opencart.com/index.php?rout ... n_id=17495
---
Image

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 421 guests