Post by Eyechild » Fri Feb 24, 2012 5:06 am

@ Calcite

Fortunately there aren't that many files that you will need to open.

You need to add this to your Register Controller which can be found at:
/catalog/controller/account/register.php

Code: Select all

public function captcha() {
	$this->load->library('captcha');
		
	$captcha = new Captcha();
		
	$this->session->data['captcha'] = $captcha->getCode();
		
	$captcha->showImage();
}
Place it at the bottom directly before the final closing curly bracket }

Then in the same file, locate the function named validate() and add this directly before the if(!$this->error) {

Code: Select all

if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
      	$this->error['captcha'] = $this->language->get('error_captcha');
}
Then again still in the same file locate this line: if (isset($this->error['zone'])) { and directly before it put this in:

Code: Select all

if (isset($this->error['captcha'])) {
	$this->data['error_captcha'] = $this->error['captcha'];
} else {
	$this->data['error_captcha'] = '';
}
And still one more thing for this file. Find this line: if (isset($this->request->post['zone_id'])) { and directly before it add this:

Code: Select all

if (isset($this->request->post['captcha'])) {
	$this->data['captcha'] = $this->request->post['captcha'];
} else {
	$this->data['captcha'] = '';
}	
Now open up your Register Language file located at: /catalog/language/YOUR LANGUAGE/account/register.php and add this:

Code: Select all

$_['entry_captcha']  = 'Enter the code in the box below:';
$_['error_captcha']  = 'Verification code does not match the image!';
And now finally open up your Register Template file located at: /catalog/view/theme/YOUR THEME/template/account/register.tpl and scroll to the bottom of the <form> element and look for this line:
<div class="buttons">, now add this directly before it on its own line:

Code: Select all

<br />
    <b><?php echo $entry_captcha; ?></b><br />
    <input type="text" name="captcha" value="<?php echo $captcha; ?>" />
    <br />
    <img src="index.php?route=information/contact/captcha" alt="" />
    <?php if ($error_captcha) { ?>
    <span class="error"><?php echo $error_captcha; ?></span>
    <?php } ?>
    <br />
That should get everything up and running for a CAPTCHA on your registration form.

Newbie

Posts

Joined
Tue Feb 21, 2012 12:52 pm

Post by philbydevil » Fri Feb 24, 2012 6:21 am

Have created a vQmod for the changes that I had to make to get this to show/work:
form-contact-page.jpg

form-contact-page.jpg (28.07 KiB) Viewed 5365 times

vQmod can be found here: http://forum.opencart.com/viewtopic.php?f=131&t=54232

Thanks again to Eyechild for all the help!

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by Eyechild » Fri Feb 24, 2012 6:51 am

@ philbydevil

Awesome!

Newbie

Posts

Joined
Tue Feb 21, 2012 12:52 pm

Post by Calcite » Fri Feb 24, 2012 7:59 am

Thanks a lot for taking the time and patience to add the post.

I have almost got it working but get the following error on the register page when I try to register a new account...


Notice: Undefined variable: entry_captcha in /Applications/MAMP/htdocs/catalog/view/theme/My_Theme/template/account/register.tpl on line 149


I am not sure if I have entered the code in the correct place in the template/account/register.tpl file

There are two "<div class="buttons">"

and here is where I have entered it

Code: Select all

 </div>    
<br />
    <b><?php echo $entry_captcha; ?></b><br />
    <input type="text" name="captcha" value="<?php echo $captcha; ?>" />
    <br />
    <img src="index.php?route=information/contact/captcha" alt="" />
    <?php if ($error_captcha) { ?>
    <span class="error"><?php echo $error_captcha; ?></span>
    <?php } ?>
    <br />
<?php if ($text_agree) { ?>
    <div class="buttons">
      <div class="right"><?php echo $text_agree; ?>
        <?php if ($agree) { ?>
        <input type="checkbox" name="agree" value="1" checked="checked" />
        <?php } else { ?>
        <input type="checkbox" name="agree" value="1" />
        <?php } ?>
        <a onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a></div>
    </div>
    <?php } else { ?>
    <div class="buttons">
      <div class="right"><a onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a></div>
    </div>
    <?php } ?>
  </form>
  <?php echo $content_bottom; ?></div>
The text "Enter the code in the box below" doesn't appear on the register page either.

I'm nearly there, I can see the Captcha image on the page ;D

Active Member

Posts

Joined
Fri Dec 30, 2011 3:21 am

Post by Eyechild » Fri Feb 24, 2012 8:13 am

@ Calcite

If you are getting an undefined variable error then you need to be looking at your Register Controller file. Looking back at what I wrote up there I forgot to mention that you need to add another variable. Look for the line like this:
$this->data['entry_confirm'] = $this->language->get('entry_confirm');
And directly after it add:

Code: Select all

$this->data['entry_captcha'] = $this->language->get('entry_captcha');
That will assign $entry_captcha to whatever text you defined in your Register Language file.

Hope it works after this! Oh, and your form looks fine. I did forget that there would be two buttons on the page, but you've got it in the correct place.

Newbie

Posts

Joined
Tue Feb 21, 2012 12:52 pm

Post by Calcite » Fri Feb 24, 2012 8:30 am

Yes.... :)

Working, and I thank you so much for the help and the time you have taken to work this out.

It is something I wanted to add to protect the registration page and I think it would be great if a Mod could make this a sticky post for others to use in their OC site.

Attachments

catcha.jpg

catcha.jpg (21.05 KiB) Viewed 5355 times


Active Member

Posts

Joined
Fri Dec 30, 2011 3:21 am

Post by SkipperTheEyechild » Fri Feb 24, 2012 9:02 am

Just a quick note, I've updated my account to be SkipperTheEyechild rather than just Eyechild. It was getting a little too hippie for me O0 .... and I think I was tired when I made that first username. Besides, this is a far better homage to Garth Marenghi's Darkplace.

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana

Post by philbydevil » Fri Feb 24, 2012 9:15 am

Calcite wrote: I think it would be great if a Mod could make this a sticky post for others to use in their OC site.
I'll look at making it into a vQmod if there isn't already one out there.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by philbydevil » Fri Feb 24, 2012 3:11 pm

philbydevil wrote:
Calcite wrote: I think it would be great if a Mod could make this a sticky post for others to use in their OC site.
I'll look at making it into a vQmod if there isn't already one out there.
vQmod for captcha on account registration page is here: http://forum.opencart.com/viewtopic.php?f=131&t=54255

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by philbydevil » Sat Feb 25, 2012 2:05 pm

I'm trying to add drop-down boxes for the country and state/zone.

Can someone please take a look and see why it isn't working when I click on "submit"? Also, the state/zone drop down usually autofills (to the first available option) in account/register (where this code came from), but here, if doesn't auto-fill and I have to change countries to have the zone list refresh.

Ok, so I can now submit the form, but the email that is sent has the country and zone as numbers (eg. zone 194, country 13). How do we clean this up so it returns as QLD, AUSTRALIA, rather than numbers.

It will have something to do with this code:

Code: Select all

			$email_body = 'Contact Person: ' . $this->request->post['name'] . "\n\r";
			$email_body .= '' . $this->request->post['company'] . "\n\r";
			$email_body .= '' . $this->request->post['street_address'] . "\n\r";
			$email_body .= '' . $this->request->post['street_address_2'] . "\n\r";
			$email_body .= '' . $this->request->post['suburb'] . "\n\r";
			$email_body .= '' . $this->request->post['zone_id'] . "\n\r";
			$email_body .= '' . $this->request->post['postcode'] . "\n\r";
			$email_body .= '' . $this->request->post['country_id'] . "\n\r";
			$email_body .= 'Phone: ' . $this->request->post['phone'] . "\n\r";
			$email_body .= 'Mobile: ' . $this->request->post['mobile'] . "\n\r";
			$email_body .= 'Email: ' . $this->request->post['email'] . "\n\r";
			$email_body .= 'Website: ' . $this->request->post['website'] . "\n\r";
			$email_body .= 'Comments: ' . $this->request->post['enquiry'] . "\n\r";
Updated xml attached.

EDIT: removed non-functioning xml
Last edited by philbydevil on Thu Mar 01, 2012 9:22 am, edited 1 time in total.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by SkipperTheEyechild » Sat Feb 25, 2012 11:50 pm

@ philbydevil

If you want to get the country and zone names in your e-mail you'll need to follow a few clues located in the Register Template, and then in the Register Controller. In the Register Template you will find this line when it begins the foreach() loop to generate countries:

Code: Select all

<select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php?route=account/register/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>');">
That part "route=account/register/zone&country_id", if you follow that route it will lead you to the folder/file/function being called. In this case you are looking for the zone() function in the Register Controller. In here you are going to find that a model is loaded by this line:

Code: Select all

$this->load->model('localisation/zone');
And if you look in the model/localisation folder, you will find the zone.php file AND another file called country.php. If you search in the Register Controller file for:

Code: Select all

$this->load->model('localisation/country');
You will see that it is already being called in a couple of places. The one that should be of particular interest is located within the validate() function where it shows you how to collect the country name by using the $this->request->post['country_id'] variable:

Code: Select all

$this->load->model('localisation/country');
		
$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);
And if you want to get the zone using the zone_id:

Code: Select all

$this->load->model('localisation/zone');

$zone = $this->model_localisation_zone->getZones($this->request->get['zone_id']);
Now both models and their respective function calls need to be used within your index() function when you are generating your e-mail. Now be aware that each of these functions are returning an array of values. If you want to learn what they are the simplest solution is to load up phpMyAdmin (or your database editor of choice) and locate the "country" table and the "zone" table. However, to save you time, I'll go ahead and tell you that you want to access the zone name and country name like this:

Code: Select all

$this->load->model('localisation/country');
		
$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);

$email_body .= '' . $country['name'] . "\n\r";
and your zone as such:

Code: Select all

$this->load->model('localisation/zone');
		
$zone = $this->model_localisation_zone->getZone($this->request->post['zone_id']);

$email_body .= '' . $zone['name'] . "\n\r";
Hope that helps. I've got to get back to packing and moving!
Last edited by SkipperTheEyechild on Tue Feb 28, 2012 2:32 am, edited 1 time in total.

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana

Post by philbydevil » Mon Feb 27, 2012 7:16 am

Thanks Skipper. I tried that code (in a few different spots) but most of the time it broke the page, or just didn't work (the email was blank in the zone/country spots).

I already have some of that code (eg. $this->load->model('localisation/country');) in my file. It's these two that I'm not sure where to put:

Code: Select all

$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);

Code: Select all

$zone = $this->model_localisation_zone->getZones($this->request->get['zone_id']);

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by SkipperTheEyechild » Tue Feb 28, 2012 2:37 am

@ philbydevil

Okay. Seems I was in a bit too much of a rush when I wrote that last post. I made a few small edits to it and I am returning country name and zone name in my e-mail now.

What I did wrong was requested Zone_ID using the $this->request->get['zone_id'], when the GET needs to be POST. I also called the wrong function. It is getZone() singular, I added an 's' to it before. So it should look like this:

Code: Select all

$zone = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
As to where it is supposed to go, just put these in right when you are creating your e-mail body. Call the model file, assign the results of the requested method to a variable, and then tack those results into the $email_body variable:

Code: Select all

$this->load->model('localisation/country');
$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);
$email_body = '' . $country['name'] . "\n\r";

$this->load->model('localisation/zone');
$zone = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
$email_body .= '' . $zone['name'] . "\n\r";
So in your case for the XML file you've got provided up above, this should go in right around line 229 where you begin defining your $email_body variable.

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana

Post by philbydevil » Tue Feb 28, 2012 6:00 am

Thanks. The zone seems to work fine on its own, but when I add in the country, almost all of the other info disappears from the email.

If I use the zone and country by itself, then they display fine on the email.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by SkipperTheEyechild » Tue Feb 28, 2012 6:16 am

Can you post your new XML file and I can take a look at it. The one with these code calls for country and zone.

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana

Post by philbydevil » Tue Feb 28, 2012 6:25 am

Here it is:

EDIT: Removed non-functioning xml
Last edited by philbydevil on Thu Mar 01, 2012 9:21 am, edited 1 time in total.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by SkipperTheEyechild » Tue Feb 28, 2012 7:15 am

@ philbydevil

When I plug that code for the Zone and Country into my Contact Form Controller I am getting the full country name and the full zone name.

I'd recommend renaming the $country variable when you are sending your e-mail to something unique. $country_full_name or something like that, because looking through the XML file it appears that $country is rather ambiguous and may be causing your problem. See if that helps first.

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana

Post by philbydevil » Tue Feb 28, 2012 9:17 am

Haven't had a chance to re-test and now I've got to get on a plane. Will try it in a couple of days. Thanks Skipper.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by philbydevil » Thu Mar 01, 2012 9:21 am

So I found a typo that got in there somehow:

Code: Select all

$email_body = 'Country: ' . $country['name'] . "\n\r";
It was missing a .

Should have been:

Code: Select all

$email_body .= 'Country: ' . $country['name'] . "\n\r";
That's what was causing my problems.

vQmod thread (http://forum.opencart.com/viewtopic.php?f=131&t=54232) has been updated with a zip file containing the new, working xml for general use.

Thanks again Skipper!

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by SkipperTheEyechild » Thu Mar 01, 2012 12:37 pm

@ philbydevil

Wonderful! Glad you found it. Those blasted concatenation operators disappear so easily!

User avatar
New member

Posts

Joined
Fri Feb 24, 2012 8:58 am
Location - Montana
Who is online

Users browsing this forum: No registered users and 351 guests