Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Age Calculation

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #21  
Old 05-06-2010, 05:23 AM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

gb,

I struggled with java vs php. I understand just enough to be dangerous with both. However Java is easier and code is more widely available.

I've looked into PHP Age caculators and I've found a few. I'm just drawing a blank on how to make it work in my X-Cart.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #22  
Old 05-08-2010, 10:27 AM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

I tried messing around with PHP code this week and I can get it to pull the extra field variables, but It's not displaying correctly on the site.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #23  
Old 05-08-2010, 02:44 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Age Calculation

Quote:
Originally Posted by minfinger
I tried messing around with PHP code this week and I can get it to pull the extra field variables, but It's not displaying correctly on the site.

That's a blanket problem, like "My car doesn't work".
Nothing can help unless you actually describe what doesn't work :P

Is it displaying at all?
If you have it and it's own div in an {if} section, does the div show up and the variable is just missing?
__________________
- Shane Munroe
Reply With Quote
  #24  
Old 05-08-2010, 02:48 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

Here's the code in the tpl.

Code:
{* For http://forum.x-cart.com/showthread.php?t=53578 Call extra fields via this: {$extra_fields.0.field_value} {$extra_fields.1.field_value} {$extra_fields.2.field_value} *} var day = {$extra_fields.0.field_value}; var month = {$extra_fields.1.field_value}; var year = {$extra_fields.2.field_value}; function checkCurAge($year,$month,$day='') { $day=(empty($day))?'1':$day; list($this_year, $this_month, $this_day) = explode(' ',date('Y n j')); $age = $this_year - $year; if ($month>$this_month||($this_month==$month&&$this_day<$day)) { $age--; } return $age; }

Here is the error. As you can see it's pull in the variables.

Error: Smarty error: [in modules/Age_Calculation/age.tpl line 12]: syntax error: unrecognized tag: $day=(empty($day))?'1':$day; list($this_year, $this_month, $this_day) = explode(' ',date('Y n j')); $age = $this_year - $year; if ($month>$this_month||($this_month==$month&&$this_d ay<$day)) { $age--; (Smarty_Compiler.class.php, line 446) in /home/minfinge/public_html/littlepuppiesonline.com/include/lib/smarty/Smarty.class.php on line 1093
var day = 8; var month = 17; var year = 1977; function checkCurAge($year,$month,$day='') return $age; }
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #25  
Old 05-08-2010, 03:19 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Age Calculation

php code does not go in the tpl files - it goes in the php files.

Perhaps you are closer to your desired result with the javascript as Tal has already provided code to you that works and you are more comfortable with javascript. If you are having trouble with the submit form, try taking that out - there is no reason for it as you are getting the data from extra fields, not a submission by the user.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #26  
Old 05-08-2010, 03:23 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

GB2...I have not gotten the Javascript to display the age calculation yet.


Look below "Our Price" It says Results.
http://littlepuppiesonline.msidesigns.com/product.php?productid=1&cat=10&page=1
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #27  
Old 05-08-2010, 03:41 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Age Calculation

One possible issue - you have a form inside a form - which is not valid html.

I've not looked at the javascript - but maybe Tal can comment about where to put this code?

If you want it inside the main form - maybe drop the form submission and just use the javascript date functions you have to output the data without a form submission
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #28  
Old 05-08-2010, 03:43 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

Quote:
Originally Posted by gb2world
One possible issue - you have a form inside a form - which is not valid html.

I've not looked at the javascript - but maybe Tal can comment about where to put this code?

If you want it inside the main form - maybe drop the form submission and just use the javascript date functions you have to output the data without a form submission

Actually that's what I'd prefer to do is just display the calc answer without the form.

The form is only there because that's what came in the code I found online.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #29  
Old 05-08-2010, 04:01 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Age Calculation

Just noticed that when Tal told you he does not see the <form> in firebug, you suggested that maybe it was firefox. Firebug often does not display incorrect code. You'll see it in the page source, but firebug does not know what to do with it since it is wrong.

Seems to me that this is even more evidence that your problem is that your age form is being incorrectly placed inside another form. If so - your solution is to move it to a valid location or revise the javascript you have copied to not use a form submission. You could verify that this is indeed the problem by trying to move that form to a valid location.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #30  
Old 05-08-2010, 04:07 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation

Quote:
Originally Posted by gb2world
Just noticed that when Tal told you he does not see the <form> in firebug, you suggested that maybe it was firefox. Firebug often does not display incorrect code. You'll see it in the page source, but firebug does not know what to do with it since it is wrong.

Seems to me that this is even more evidence that your problem is that your age form is being incorrectly placed inside another form. If so - your solution is to move it to a valid location or revise the javascript you have copied to not use a form submission. You could verify that this is indeed the problem by trying to move that form to a valid location.

I'd rather have the script not use the form and then I'd be able to place the tpl call where ever I wanted.

Only problem is I don't understand how to display the age calc answer using java. Any help would be great.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:53 AM.

   

 
X-Cart forums © 2001-2020