Post by SubatWest » Thu Oct 13, 2016 8:40 pm

hi artcore

New topic to cover query
Thanks

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Thu Oct 13, 2016 9:20 pm

I know where to find the original post but no one else will!
Please include a detailed question with properly formatted forum styles (

Code: Select all

,[img]etc) to encourage members to answer ;)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Thu Oct 13, 2016 9:31 pm

Hi artcore

You kindly helped with an issue recently. I have now added (Successfully) a 'subject' box in my contact form. Can you help me turn this into a drop down list with some options? Thanks for any assistance.

I added to Catalog/controllor/information/contact.php

if (isset($this->request->post['reason'])) {
$data['reason'] = $this->request->post['reason'];
} else {
$data['reason'] = '';
}

and also added

if ((utf8_strlen($this->request->post['reason']) < 1)) {
$this->error['reason'] = $this->language->get('error_reason');
}
and also ammended

$mail->setText($this->request->post['enquiry'] . to

$mail->setText($this->request->post['enquiry'] . $mail->newline . 'reason: ' . $this->request->post['reason']);
$mail->send();

and also added

$data['entry_reason'] = $this->language->get('entry_reason');

and also added

if (isset($this->error['reason'])) {
$data['error_reason'] = $this->error['reason'];
} else {
$data['error_reason'] = '';

if (isset($this->request->post['reason'])) {
$data['reason'] = $this->request->post['reason'];
} else {
$data['reason'] = '';
}

and also added

if ((utf8_strlen($this->request->post['reason']) < 1)) {
$this->error['reason'] = $this->language->get('error_reason');
}


In the catalog/language/Englis/Information/contact.php i added

$_['entry_reason'] = 'Subject'; under Text

$_['entry_reason'] = 'Subject'; under Entry

$_['error_reason'] = 'Please choose a subject!';

In the catalog/view/theme/default/template/information/contact.tpl I added

<div class="form-group required">
<label class="col-sm-2 control-label" for="input-reason"><?php echo $entry_reason; ?></label>
<div class="col-sm-10">
<input type="text" name="reason" value="<?php echo $reason; ?>" id="input-reason" class="form-control" />
<?php if ($error_reason) { ?>
<div class="text-danger"><?php echo $error_reason; ?></div>

I stress I am not a coder but worked this out and it has done the job well with a static box. However, I would like a drop down list to make reason for contact clearer. Is that possible and what would I alter in the code?
Thanks
Martin

SubatWest

Posts: 30
Joined: Thu Oct 30, 2014 6:29 pm

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Thu Oct 13, 2016 9:53 pm

language:
$_['reason1']='I need a quote';
$_['reason2']='I need an offer';
$_['reason3']='I need more information';
$_['error_reason'] = 'please give us a reason';

controller:
create an array with your choices. I made them multi-lingual

Code: Select all

$data['reasons']   = array(
				$this->language->get('reason1'),
				$this->language->get('reason2'),
				$this->language->get('reason3'),
			);
initialize the post var

Code: Select all

$data['reason'] = isset($this->request->post['reason']) ? $this->request->post['reason'] : '';
Do some checking

Code: Select all

protected function validate() {
 if ($this->request->post['reason'] == '') {
  $this->_error['reason'] = $this->language->get('error_reason');
 }
 ///etc
}
template:

Code: Select all

<div class="form-group">
	<div class="input-group">
		<select title="---select---" class="form-control" name="reason">
			<option value="">reasons</option>
<!--here you are looping the array-->
			<?php foreach ($reasons as $option) { ?>
				<option value="<?php echo $option ?>"

<!-- if someone made a choice and hit save but there was an error, put the posted var back as chosen-->
					<?php if ($option === $reason) {
						echo ' selected="selected"';
					} ?>>
					<?php echo $option ?>
				</option>
			<?php } ?>
		</select>
	</div>

<!-- this will activate upon error-->
	<?php if ($error_reason) { ?>
		<div class="label label-danger"><?php echo $error_reason; ?></div>
	<?php } ?>
</div>
Untested but should at least give you an idea!
...and next time please take the time to post a readable query... ;)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Thu Oct 13, 2016 11:22 pm

Hi Again

Have made all thge suggested code entries and get the following error:

Parse error: syntax error, unexpected 'protected' (T_PROTECTED) in C:\xampp\htdocs\kevinkirby\vqmod\vqcache\vq2-catalog_controller_information_contact.php on line 211

Have tried to make sure the code is entered at the correct places and rearranged some blocks but no change.

Advice?
Regards and thanks and I do note you comments for future.
Martin

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Fri Oct 14, 2016 2:08 am

NP;)
I wrote out of habit _error for a private var. That's probably it.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Fri Oct 14, 2016 6:02 am

Hi nearly there!

Using your starting point there were a number of issues when I finally got it to appear.

This has been the sequence of code I used.

In the catalog/controller/information/contact.php:

Code: Select all

$data['text_reason'] = $this->language->get('text_reason');


$data['entry_reason'] = $this->language->get('entry_reason');

$data['reasons']   = array(
                $this->language->get('reason1'),
                $this->language->get('reason2'),
                $this->language->get('reason3'),
                $this->language->get('reason4'),
             );

if (isset($this->error['reason'])) {
$data['error_reason'] = $this->error['reason'];
} else {
$data['error_reason'] = '';
}

  $data['reason'] = isset($this->request->post['reason']) ? $this->request->post['reason'] : '';
In the Catalog/language/english/information/contact.php:

Code: Select all

// Text
$_['text_reason']   = 'Reason for contact';

//Entry
$_['entry_reason']   = 'Reason for enquiry';

//Errors
$_['error_reason']   = 'Please give a reason for contact';
In the catalog\view\theme\default\template\information:

Code: Select all

             <div class="form-group required">
                 <label class="col-sm-2 control-label" for="input-reason"><?php echo $entry_reason; ?></label>
                 <div class="col-sm-10">
           <div class="input-group">
          <select title="---select---" class="form-control" name="reason">
             <option value="">reasons</option>
    <!--here you are looping the array-->
             <?php foreach ($reasons as $option) { ?>
                <option value="<?php echo $option ?>"

    <!-- if someone made a choice and hit save but there was an error, put the posted var back as chosen-->
                   <?php if ($option === $reason) {
                      echo ' selected="selected"';
                   } ?>>
                   <?php echo $option ?>
                </option>
             <?php } ?>
          </select>
       </div>

    <!-- this will activate upon error-->
       <?php if ($error_reason) { ?>
          <div class="label label-danger"><?php echo $error_reason; ?></div>
       <?php } ?>
    </div>
     </div>
Your code for the controller I cannot get to work at all:

Code: Select all

protected function validate() {
 if ($this->request->post['reason'] == '') {
  $this->_error['reason'] = $this->language->get('error_reason');
 }
 ///etc
}
The attached screenshot is the result of the above code.
When the submit button is pressed the 'success' appears and the email is sent and received. However, the reason is not included in the email.

Can I have your commenst artcore as to anything I need to do. Certainly helping me learn a lot of coding! :)

Thanks

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by SubatWest » Fri Oct 14, 2016 6:05 am

Oops
forgot one piece of code in Language:

Code: Select all

$_['entry_reason']   = 'Reason for enquiry';
$_['reason1']='General';
$_['reason2']='Sales';
$_['reason3']='Delivery';
$_['reason4']='Hire';
That's it!

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Fri Oct 14, 2016 3:28 pm

Are you calling the validation method from if POST && $this->validation() ?
I only gave an example for it, hence the 'etc...',
You can look at how the original validation() is coded and add the check I provided in that example.

I did forget to initialise the error message, so well done there :D

PS can't make out the error you got from the docx, my tablet only shows half a blue line...

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Fri Oct 14, 2016 4:06 pm

Hi artcore

Thanks for response.

There is no error in the screenshot the form has the box and drop down. I do not understand your comment as I am just learning. What do you mean by 'Are you calling the validation method from if POST && $this->validation() ?'
Is that why the reason is not appearing in the email that is sent?

Thanks

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Fri Oct 14, 2016 5:40 pm

In the controller file, find && $this->validation(). You see it's part of the if condition: if(...POST meaning if there is a POST/submit form it will go through the checks in that method before continuing to send the mail.

You can add the 'reason' to the array that's sent to the mail template but you also have to add something to it in order to display it in the actual mail sent.
I think the template is located at catalog/view/theme/default/template/mail/contact.tpl ? or just check the controller which tpl is used. See how it echoes the enquiry variable? Do something similar to $reason.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Fri Oct 14, 2016 7:02 pm

Hi artcore

OK I have now looked at other coding in the controller and have changed the isset and this has made the check correct. So every thing is working on the form but it is now only the email not including the reason. There is no mail contact.tpl but in the controller there is this:

Code: Select all

	$mail->setTo($this->config->get('config_email'));
			$mail->setFrom($this->request->post['email']);
			$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
			$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
		        $mail->setText($this->request->post['reason']);
			$mail->setText($this->request->post['enquiry']);
                       	$mail->send();
You will see I added ' $mail->setText($this->request->post['reason']);' thinking this would do the job but no luck. There is obviously a setting here that I am missing - frustratingly close....

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Fri Oct 14, 2016 7:34 pm

Ah that's why I didn't remember the tpl for this mail, there isn't one, lol

So build out a $text var and use this for the setText method

Code: Select all

$text = 'Reason: ' . $this->request->post['reason'] . PHP_EOL;//end of line. Can also use "\r\n" in double quotes!
$text .= $this->request->post['enquiry'];

optional extra texts, you decide:
$text .= 'Thank you for containg us';

...
$mail->setText($text);
For a nicely formatted html email
$mail->setHTML($text);

But you have to create a valid hml page inculding headers!

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by SubatWest » Fri Oct 14, 2016 7:55 pm

Many thanks artcore. With a bit of experiementing finallt got there!

Really appreciate your input.

Thanks

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by artcore » Fri Oct 14, 2016 9:23 pm

You're welcome! Enjoy ;D

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands
Who is online

Users browsing this forum: Bing [Bot] and 12 guests