Zen Cart Logo
Forums / General Questions / Trying to add help text in Coupon code field

Trying to add help text in Coupon code field

Views: 821

Results 1 to 5 of 5
14 Jan 2016, 11:51 AM
#1
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Trying to add help text in Coupon code field

I want to add some descriptive text on the promo code field that says "enter your promo code!", so firstly i added a new define to includes/languages/english/modules/order_total/ot_coupon.php

define('CODE_SUBMIT_DEFAULT_TEXT','enter your promo code!');

I then changed line 137 of includes/modules/order_total/ot_coupon.php from

'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),

to

'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)" class="promo-code-box" value="' . CODE_SUBMIT_DEFAULT_TEXT . '" onfocus="if (this.value == '' . CODE_SUBMIT_DEFAULT_TEXT . '') this.value = '';" onblur="if (this.value == '') this.value = '' . CODE_SUBMIT_DEFAULT_TEXT . '';"'),

followed by changing line 158 from

if ((isset($_POST['dc_redeem_code']) && $_POST['dc_redeem_code'] != '') || (isset($discount_coupon->fields['coupon_code']) && $discount_coupon->fields['coupon_code'] != '')) {

to

if ((isset($_POST['dc_redeem_code']) && $_POST['dc_redeem_code'] != '' && ($_POST['dc_redeem_code'] != CODE_SUBMIT_DEFAULT_TEXT)) || (isset($discount_coupon->fields['coupon_code']) && $discount_coupon->fields['coupon_code'] != '')) {

The problem I have is that when I click the Continue button, checkout does not move to the next step. If I remove the edit from line 158, I get the message stack warning to say that the coupon code is invalid due to the value of CODE_SUBMIT_DEFAULT_TEXT being stored.

Looking at the code, I thought that the if statement at line 158 was what was checking for a blank field, i.e. no coupon code present, and so telling it to ignore the entry if it matched the define would be sufficient. Obviously not.

Any suggestions on what else might be amiss here?

15 Jan 2016, 9:56 PM
#2
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Re: Trying to add help text in Coupon code field

Nobody got any ideas on this?

19 Jan 2016, 9:48 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Trying to add help text in Coupon code field

You could use the HTML5 "placeholder" attribute instead of the old approach of injecting a bunch of javascript which might have a mismatched set of quotation marks thus causing your form to break.
Most modern browsers support the HTML5 placeholder markup even on non-HTML5 templates, so this should work for most visitors.

Thus, this:
'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),

could become something like this:

'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)" placeholder="' . addslashes(CODE_SUBMIT_DEFAULT_TEXT) . '" '),
19 Jan 2016, 11:48 PM
#4
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Re: Trying to add help text in Coupon code field

I did look at "placeholder" DrByte, but when I tried it the text stayed visible on the input field even after entering a coupon code. Whether that was due to an error, or the way "placeholder" works, I don't know.

20 Jan 2016, 4:45 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Trying to add help text in Coupon code field

strelitzia:

The problem I have is that when I click the Continue button, checkout does not move to the next step.
That happens when the generated HTML isn't fully valid ... which is typically caused by mismatched single-quotes or double-quotes (which could be inside your language-constant), or extra/missing < or > symbols. (Or nesting forms inside each other, which I'm pretty sure isn't what you're doing here.)

Running the page source (right-click, choose View Page Source) through an HTML validator to show you which HTML tags are incorrect is a good starting point.