X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Click "I agree" checkbox before allowing purchase. (https://forum.x-cart.com/showthread.php?t=15144)

TP 07-12-2005 07:56 AM

Click "I agree" checkbox before allowing purchase.
 
A client has asked me to implement some code whereby a customer must agree that they have read, and agree to, their Terms and conditions, otherwise they are not able to continue with a purchase. The customer has to tick the "I agree" checkbox etc.

Has anyone done a similar thing? If so, can you give me some guidance as to how to do this please?

Note: FWIW, there is nothing dodgy about the client or the products they want to sell, they just want to be a little cautious is all! :)

Many thanks.

TP 07-15-2005 12:28 AM

Any ideas or suggestions anyone :?:

TelaFirma 07-15-2005 03:49 AM

...edited to reflect changes made later on in this post...

Here is a mod that will hide the submit button until they check the box that they agree.

Step 1
Create the file /skin1/hide_block_script.tpl with this contents:
Code:

{literal}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
// Function to flip visibility of certain div objects
function flipdiv(el,state) {
  if(state=="show"){
      status="block";
  }else{
      status="none";
  }
  document.getElementById(el).style.display = status;
}
</SCRIPT>
{/literal}


Step 2
Open the file /skin1/customer/main/checkout.tpl for editing.
At top of the file right before the first {capture} insert the line

Code:

{include file="hide_block_script.tpl"}

Next look for the line:
Code:

{$lng.txt_you_are_agree} "{$lng.lbl_terms_n_conditions}" {$lng.lbl_and} "{$lng.lbl_privacy_statement}".
and add this right after it:

Code:



No<input type="radio" name="agree" checked="checked" onclick="flipdiv('checkoutbutton','hide')" /> Yes<input type="radio" name="agree" onclick="flipdiv('checkoutbutton','show')">I Agree to the Terms and Conditions


Next find the section that looks like:
Code:

{include file="buttons/button.tpl" button_title=$lng.lbl_submit_order style="button" href=$button_href}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if}


and change it to read:

Code:

<div align="center">
<table border=0 cellpadding="0" cellspacing="0" id="checkoutbutton" style="display: none;">
<tr><td>
{include file="buttons/button.tpl" button_title=$lng.lbl_submit_order style="button" href=$button_href}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if}
</td></tr>
</table>
</div>


TP 07-15-2005 04:41 AM

:D Superb idea TelaFirma. Thanks for taking the time to compile the solution, I'm sure this will be useful to others too.

Only 1 little problem with the final piece of code:
Code:

<div align="center">
<table border=0 cellpadding="0" cellspacing="0" id="checkoutbutton" style="display: none;">
<tr><td>
{include file="buttons/button2.tpl" button_title=$lng.lbl_submit_order style="button" href=$button_href}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if}
</td></tr>
</table>
</div>


It should read:
Code:

<div align="center">
<table border=0 cellpadding="0" cellspacing="0" id="checkoutbutton" style="display: none;">
<tr><td>
{include file="buttons/button.tpl" button_title=$lng.lbl_submit_order style="button" href=$button_href}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if}
</td></tr>
</table>
</div>


The only difference is the button template called by the include code, it should be "button.tpl" and not "button2.tpl". Once I changed that your code work perfectly.

Thank you!

TelaFirma 07-15-2005 05:09 AM

Oops... my fault! That is a secondary button template that I am using on one of my sites.. LOL

I will correct the post.

TP 07-15-2005 05:28 AM

Cool.

I've noticed that if you tick the checkbox, everything is fine. But if you untick the checkbox, the submit order button is still displayed.

I've done something similar with show/hide using DIVs, and I've been comparing code etc to find the solution for this, but no luck so far with my tests.

Can you see why it doesn't toggle the order button?

Thanks.

TelaFirma 07-15-2005 06:08 AM

I think that it will be best to use a radio button here rather than a checkbox. Since it is using the onclick method to call the function there is not a good way to check for a second click on the checkbox. Otherwise you would need to submit the form and check the state of the box and that would defeate the purpose of the script. So, lets use the radio buttons instead...

Change
Code:


<input type="checkbox" onclick="flipdiv('checkoutbutton','show')"> I Agree to the Terms and Conditions


to be

Code:



No<input type="radio" name="agree" checked="checked" onclick="flipdiv('checkoutbutton','hide')" /> Yes<input type="radio" name="agree" onclick="flipdiv('checkoutbutton','show')">I Agree to the Terms and Conditions


I will update the original post again to reflect this...

TP 07-15-2005 06:47 AM

Thanks, that works really well. Whilst you were doing that, I had a go at using some other code I'd used in the past to show/hide layers and got it to work with the checkbox. I used your code in the end, but this also works:

Here is the code:

hide_block_script.tpl
Code:

{literal}
<script>
function toggle(theImg, divName){
  if(theImg.value!='on'){
    theImg.value='on'
  } else {
    theImg.value='off'
  }
  divStyle = document.getElementById(divName).style;
  if(theImg.value=='on'){
    divStyle.display='block';
  } else {
    divStyle.display='none';
  }
}
</script>
{/literal}


Skin1\customer\main\checkout.tpl:
Code:

{include file="hide_block_script.tpl"}

Code:


<input type="checkbox" name="checkbox" value="checkbox" onclick="toggle(this,'wrapper');"> I Agree to the Terms and Conditions


Code:

<div id="wrapper" style="display:none">{include file="buttons/button.tpl" button_title=$lng.lbl_submit_order style="button" href=$button_href}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if} </div>


mukunig 11-07-2005 06:33 PM

This is great, thanks. I am having a problem however. I used the code from TelaFirma --now I get the radio buttons and when the customer clicks the Yes radio button the submit button appears. My problem is that the radio button for No continues to be checked as well. It is confusing to have both the Yes and No buttons checked at the same time. Is there a way to turn off the No button when the Yes button is checked?

Thanks for your help.

X-cart Pro 4.0.13 with lots of modifications

Realsecurity 11-14-2005 05:44 AM

After changing the code as suggested i now have this error message wich displays on site next to the бё signs?

Warning: Smarty error: unable to read resource: "customer/main/alter_currency_value.tpl" in /home/realsecu/public_html/Smarty-2.6.3/Smarty.class.php on line 1082

Any ideas!!!! the check boxes appear where they should!!!

teriwinkle 12-06-2005 11:01 PM

Submit buttons not working
 
I put this code in place as mentioned.. Everything seems to work except the submit button becomes non-functional. It appears after you click I agree to the terms, but you cannot click the submit order button. What could be causing that?



I am using version 3.5.14

Code:

{* $Id: checkout.tpl,v 1.37.2.1 2004/07/19 07:26:50 max

Exp $ *}
{include file="location.tpl"

last_location=$lng.lbl_payment_details}
{capture name=checkout_dialog}
<form action="cart.php" method=post name=cartform>
{if $config.Appearance.show_cart_details eq "Y" or

($config.Appearance.show_cart_details eq "L" and

$smarty.get.paymentid ne "" and $smarty.get.mode eq

"checkout")}
{include file="customer/main/cart_details.tpl"}
{else}
{include file="customer/main/cart_contents.tpl"}
{/if}
<HR noshade size=1>

{include file="customer/main/cart_totals.tpl"}



{if $js_enabled}
<a href="javascript:

document.cartform.submit()">{include

file="buttons/update.tpl"}</a>
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_update}
{/if}
</form>
{/capture}
{include file="dialog.tpl" title="`$lng.lbl_checkout`:

`$lng.lbl_step` `$checkout_step` `$lng.lbl_of`

`$total_checkout_steps`"

content=$smarty.capture.checkout_dialog

extra="width=100%"}



{if $smarty.get.mode eq "auth"}
{include file="main/error_login_incorrect.tpl"}
{/if}
{if $payment_data.payment_method ne ""}
<h5>{$lng.lbl_payment_method}:

{$payment_data.payment_method}</h5>
{capture name=dialog}
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<form action="{$payment_data.payment_script_url}"

method=post name=checkout_form>
<input type=hidden name=action value="place_order">
<tr><td>
<pre>
<font>
{include file="customer/main/customer_details.tpl"}
</font>
</pre>
<a

href="register.php?mode=update&action=cart&paymentid={$s

marty.get.paymentid}">{include

file="buttons/modify.tpl"}</a>


{if $ignore_payment_method_selection eq ""}
<div align=right>
<a href="cart.php?mode=checkout">{include

file="buttons/change_payment_method.tpl"}</a>
</div>
{/if}
{if $error eq 'fields'}

<FONT

color="red">{$lng.txt_require_cc_fields_error}</FONT>


{/if}
<input type=hidden name={$XCARTSESSNAME}

value={$XCARTSESSID}>
{if $payment_data.payment_template ne ""}
{include file=$payment_data.payment_template}
{/if}
{include file="customer/main/checkout_notes.tpl"}


<input type=hidden name=payment_method

value="{$payment_data.payment_method}">
{$lng.txt_you_are_agree} "{$lng.lbl_terms_n_conditions}"

{$lng.lbl_and} "{$lng.lbl_privacy_statement}".
<p align=center>
{if $js_enabled}
<a href="javascript: {if $config.General.check_cc_number

eq "Y" and $payment_data.payment_script eq

"payment_cc.php" and $config.disable_ccinfo ne

"Y"}if(checkCCNumber(document.checkout_form.card_number,

document.checkout_form.card_type) &&

checkExpirationDate(document.checkout_form.card_expire)

{if $config.disable_ccinfo ne "C"} &&

checkCVV2(document.checkout_form.card_cvv2,document.chec

kout_form.card_type){/if}){/if}

document.checkout_form.submit()">{include

file="buttons/submit_order.tpl" style="button"}</a>
{else}
{include file="submit_wo_js.tpl"

value=$lng.lbl_submit_order}
{/if}
</td></tr>
</form>
</table>
{/capture}
{include file="dialog.tpl"

title=$lng.lbl_payment_details

content=$smarty.capture.dialog extra="width=100%"}

{elseif $payment_methods ne ""}

{capture name=dialog}
<form method=get action="cart.php" name=checkout_form>
<table border=0 align=center>
{section name=payment loop=$payment_methods}
<tr>
<td width=1><input type=radio name=paymentid

value={$payment_methods[payment].paymentid}{if

$payment_methods[payment].is_default eq "1"}

checked{/if}></td>
<td

nowrap>{$payment_methods[payment].payment_method}&nbs

p;
</td>
<td>{$payment_methods[payment].payment_details}</td>
</tr>
{/section}
<input type=hidden name=mode value=checkout>
</table>


<div align=center>
{if $js_enabled}
<a href="javascript:

document.checkout_form.submit()">{include

file="buttons/continue.tpl" style="button"}</a>
{else}
{include file="submit_wo_js.tpl"

value=$lng.lbl_continue}
{/if}
</div>
</form>
{/capture}
{include file="dialog.tpl" title=$lng.lbl_payment_method

content=$smarty.capture.dialog extra="width=100%"}
{/if}


Thanks in advance!

Realsecurity 12-07-2005 12:02 AM

After placing the code as suggested although i had a smarty error this was caused by another mod, once complete the check button works absolutely fine, check yes SUBMIT ORDER button appears, CHECK NO submit button dissapears just like it should.......im using vers 4.13

goto www.realsecurity.co.uk try the checkout and you will see it works just fine!!!

teriwinkle 12-11-2005 09:11 PM

Problem solved
 
Okay...my problem was because there is different syntax for version 3.5.10 thent he 4.x version. This is what I needed inside the <div>

Code:

<div align="center">
<tr><td>
{if $js_enabled}
{include file="buttons/submit_order.tpl" style="button"}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_submit_order}
{/if}
</td></tr>
</table>
</div>



It works great now...Thanks for a nice mod!

2coolbaby 02-07-2006 11:20 AM

I have tried both of these methods and no Submit button shows up for me when I click on I Agree. (Checkbox div & radio button). I have 4.0.17 & I am also on a Mac using Safari. That is most likely the reason, but wanted to let you know that this method is preventing Mac users on Safari from purchasing your product. I have too many mac customers to cut them out. Have to find another method of doing this.

caviar 05-01-2007 05:14 AM

Re: Click "I agree" checkbox before allowing purchase.
 
Here is another solution.

Display the "I agree" text with a checkbox and the submit button initially. When the customer goes to click the submit button the script below checks to see if the checkbox was checked or not. If so the order goes through else a popup box is displayed telling the customer he/she must agree to the terms and conditons before placing the order.

Code:

{literal}
<script language="javascript" type="text/javascript">
function wrapperCheckTerms(formName) {
if (checkTermsBox(formName)) {
return true;
} else {
return false;
}
}

function checkTermsBox(formName) {
var alertMsg = "You must agree to our Terms and Conditions before placing this order.";
if (formName.AgreeToTermsAndConditions.checked) {
return true;
} else {
alert(alertMsg);
return false;
}
}
</script>
{/literal}


And place this code in the submit button link.

Code:

onclick='return wrapperCheckTerms(checkout_form);'

I've seen most websites operate in this matter. Check out the UPS website to see this in action. Try clicking the 'Track' button without filling out the form and you'll see what happens.

Code:

http://www.ups.com/content/us/en/index.jsx

hrothbeorht 07-10-2007 07:55 AM

Re: Click "I agree" checkbox before allowing purchase.
 
Hey there all,

I need to have this or a similar mod to run on my site. I've tried all the variations and none would even display a button of any sort. I think x-cart has evolved past where this mod works as is. I'm hoping that there are some out there that would enjoy reopening this mod for it to work with the latest stable version 4.1.8. I don't necessarily need it to hide/display just a javascript check to verify that a check box is checked.(with an alert box)

hope this catches someones interest!:P

-hroth

dave70 07-10-2007 08:10 AM

Re: Click "I agree" checkbox before allowing purchase.
 
check out this thread. I was able to implement this code in just a few minutes.

http://forum.x-cart.com/viewtopic.php?p=129976


If you want to change the text, you can find it in the languages section of your admin.

hrothbeorht 07-10-2007 09:24 AM

Re: Click "I agree" checkbox before allowing purchase.
 
Thanks Dave,
I went through the mod and it works perfectly!
Much much obliged!

-hroth

mwar 08-08-2007 01:03 PM

Re: Click "I agree" checkbox before allowing purchase.
 
I wish I had seen this before the custom modification we purchased with our script.

Lukas 11-15-2007 08:06 AM

Re: Click "I agree" checkbox before allowing purchase.
 
Hello!
I recently tried to implement a date picker within "checkout_notes.tpl". It works perfectly in html but apparently not within tpl. Do I make a very obvious mistake? Attached is the file. Thank you for any hint!! ~Jahn



{* $Id: checkout_notes.tpl,v 1.6 2005/12/07 14:07:21 max Exp $ *}
{include file="customer/main/subheader.tpl" title=$lng.txt_notes class="grey"}

<head>


<link rel="stylesheet" href="{$SkinDir}/cal-2/demos.css" media="screen" type="text/css">

<script type="text/javascript" src="{$SkinDir}/cal-2/dhtmlSuite-common.js"></script>
<script language="javascript" type="text/javascript" src="{$SkinDir}/cal-2/dhtmlSuite-calendar.js"></script>
<script language="javascript" type="text/javascript" src="{$SkinDir}/cal-2/dhtmlSuite-dragDropSimple.js"></script>
<link type="text/css" media="screen" rel="stylesheet" href="{$SkinDir}/cal-2/calendar.css">

</head>
<body>

<!-- A DATE PICKER FOR FORMS -->
{literal}
<script type="text/javascript">
var calendarObjForForm = new DHTMLSuite.calendar({minuteDropDownInterval:10,num berOfRowsInHourDropDown:5,callbackFunctionOnDayCli ck:'getDateFromCalendar',isDragable:true,displayTi meBar:true});
calendarObjForForm.setCallbackFunctionOnClose('myO therFunction');

function myOtherFunction()
{
}
function pickDate(buttonObj,inputObject)
{
calendarObjForForm.setCalendarPositionByHTMLElemen t(inputObject,0,inputObject.offsetHeight+2); // Position the calendar right below the form input
calendarObjForForm.setInitialDateFromInput(inputOb ject,'yyyy-mm-dd hh:ii'); // Specify that the calendar should set it's initial date from the value of the input field.
calendarObjForForm.addHtmlElementReference('myDate ',inputObject); // Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
if(calendarObjForForm.isVisible()){
calendarObjForForm.hide();
}else{
calendarObjForForm.resetViewDisplayedMonth(); // This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
calendarObjForForm.display();
}
}
/* inputArray is an associative array with the properties
year
month
day
hour
minute
calendarRef - Reference to the DHTMLSuite.calendar object.
*/
function getDateFromCalendar(inputArray)
{
var references = calendarObjForForm.getHtmlElementReferences(); // Get back reference to form field.
references.myDate.value = inputArray.year + '-' + inputArray.month + '-' + inputArray.day + ' ' + inputArray.hour + ':' + inputArray.minute;
calendarObjForForm.hide();

}
</script>{/literal}



<form name="myForm">
<table cellspacing="0" cellpadding="2">
<tr valign="top">
<td>{$lng.lbl_customer_notes}:</td>
<td>&nbsp;</td>
<td nowrap="nowrap"><textarea cols="70" rows="3" name="Customer_Notes" value="2007-12-24 12:00" onclick="" ></textarea></td>
<td><input value="Pick-up date/time" onclick="pickDate(this,document.forms[0].myDate);" type="button"></td>
</tr>


</table></form>
</body>


All times are GMT -8. The time now is 05:43 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.