X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   product options validation (https://forum.x-cart.com/showthread.php?t=1218)

snorocket 01-18-2003 08:53 AM

product options validation
 
is there any tutorials of furthur explanations on how to use the product validations option? i can't seem to get it to work properly, anyone have any better examples on how to use this and what it does?, thanks


Example:
if (product_option('Cover').selectedIndex == 1)
{ alert('You have chosen Hard cover for this product'); return true; }

rubberneck 02-04-2003 10:01 AM

confused
 
I am having trouble understanding the product options validation feature too. Did you figure it out?

Someone else have some help?

Is the manual/help section going to be updated soon?

snorocket 02-05-2003 11:43 AM

no luck
 
no matter what i try i can't get it to work, just displays an error on the page and then nothing works at all, does anyone know how this works, i don't beleive this many people have xcart an no one knows how to make the product validation work, rrf we explicit instructions on how to use this feature !!!!

dtherio 02-06-2003 07:08 AM

I haven't seen this option. Where is this option you are referring to?

Dale

snorocket 02-07-2003 04:57 AM

under product options
 
the validation thing is under the product options

Nico van de Putte 02-17-2003 02:04 PM

Hi,

I got this working!

You should have an option list first where you make up your own option class (for instance MEDIA)
Option Text is the displayed text. SELECT MEDIA TYPE:
Option list is the list. Something like: CD-ROM=+0
(option 1 is CD-ROM and will cost +0 of your currency over the default price)

Theproduct options validation can be used to manipulate things based on the selection made in the option list

if (product_option('MEDIA').selectedIndex == 1)
{ alert('You have chose the CD-ROM option'); return true; }

If you have more then one selectable item SELECTEDINDEX will increase by one for every new choice.

Hope this helps?

Nico

snorocket 02-18-2003 11:49 AM

yep
 
Hey Nico,

yep i got it working but i get errors when i change the ==1 part .Does anyone know what this part is suppose to do?

if (product_option('MEDIA').selectedIndex== 1)
{ alert('You have chose the CD-ROM option'); return true; }

i figured it was the option line number chioce. Example, if i had an option COLORS and on line 1 was red, line 2 green, line 3 blue, i figured i could put the validation to look like this

if (product_option('COLORS').selectedIndex == 3)
{ alert('You have chosen Color Blue'); return true; }

so the 'You have chosen Color Blue' would pop-up, but all i get is an error on the page, any clues would be great, Thanks - snorocket

Nico van de Putte 02-18-2003 02:50 PM

Hi,

Do the == 2 and == 3 work? If yes it's probably a Syntax error. Please paste it in the forum so we can check.

Nico

snorocket 02-18-2003 05:22 PM

changing the ==1 to any other number then 1 causes an error and the shopping cart does'nt work then, i'm still poking away at it slowly

Nico van de Putte 02-19-2003 09:54 AM

Stupid question: You DO have THREE color option, do you?

Just checking.... :wink:

mitchie 03-12-2004 09:59 AM

Does anybody know how to make this work for blank user input field?

Thanks.
M :?

daveb1 03-15-2004 09:05 AM

Mitchi

If you just want a field that the customer can type something about the product, say if you offer personalisation of pens or mugs and you want the customer to be able to say what they want printed on it, just type "personalisation" or whatever in the Option Class box, type "Please anter your message" in the Option Text box, and leave the Options List empty.

When the customer types the message in the box, you see it as an item option on the order.

hth

Dave

mitchie 03-15-2004 04:10 PM

Thank's, Dave! I'll give it a try.

M :)

sm00ve 03-17-2004 03:23 AM

Can anyone help finally getting this to work?
 
Here is my thinking and need. I have seen several post requesting to cange an image based on a selected option. What I need to make this happen are the variables associated with the option. (Obvious) right?

My thinking is that if exceptions (If they worked) can pop an alert, I should be able to capture the values needed to make a simple image change.

I have copied and pasted the example straight from the Product admin, and when I click add to cart it does not respond at all. The question I ask is was this tested prior to included it in the release build and if so, why not help us out if it is not working.

I need to check the forum to see if there is a Bug reporting category, but that is still not going to help the group out at all.

If there is any kind sole out there that is not going to respond to this request with psot it in the professional section so I can cash in on your pain, please help me out. I have been punding at this non-stop for 3 days now and really need assistance so I can move on to more important things like developing my product line.

Thanks you guys

George

sm00ve 03-17-2004 03:44 AM

Follow-up - break through
 
This will help the folks that simply want to get exceptions to work! Beware that if you are on a mac like I am, no alerts will pop until you do what is lsited below. I hit it on a PC and the behavior is that if there is 1 exception and 10 options, it will only alert for that single exception and proceed to the cart.

Here is the secret that is not documented anywhere:

1. If you have 10 options, you'd better make exceptions for all 10. The numbering does not start at 1, it starts at 0.

The Real example:

if (product_option('Shirt').selectedIndex == 0)
{ alert('You have chosen Color White Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 1)
{ alert('You have chosen Color Gray Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 2)
{ alert('You have chosen Color Charcoal Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 3)
{ alert('You have chosen Color Laguna Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 4)
{ alert('You have chosen Color Blue Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 5)
{ alert('You have chosen Color Orange Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 6)
{ alert('You have chosen Color Purple Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 7)
{ alert('You have chosen Color Yellow Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 8)
{ alert('You have chosen Color Red Shirt'); return true; }

if (product_option('Shirt').selectedIndex == 9)
{ alert('You have chosen Color Green Shirt'); return true; }

I am getting it to pop up with the correct color selections now. Now it's on to capturing and storing so that I can construct an image name.

Once I figure this out, I'll share it here as well. (If I am successful of course) Maybe someone else can jump in with suggestions on how to change the alert to a javascript variable that can be used in php!

to be continued ....

PhilJ 06-03-2004 05:16 AM

I have a single blank input field as a product option, for the customer to fill in a promotional code.

Any idea what validation script to use, so the option is not left blank?

Thanks
PhilJ

Adian009 06-04-2004 09:55 PM

How to Validate a Text Entry Field / Product Option
 
This example assumes you have a product option with a class of PaperColor and you want to make sure the field isn't left completely blank.

Quote:

if (product_option('PaperColor').value == '') {
alert('Paper Color must be chosen before adding to cart.');
return false;
}


The "return false;" statement stops X-Cart from adding the product to the cart.

You could also ask the user if the field is intentionally left blank using the following code:

Quote:

if (product_option('PaperColor').value == '') {
if (confirm('Add to cart with Paper Color blank?')) {
return true;
} else {
return false;
}}

The confirm is like an alert except it has "OK" and "CANCEL" buttons. If the user clicks "OK" the product will be added, if they click "CANCEL" it will not be added.

If you need any other JavaScript validation help let me know - I know JS like the back of my hand.

Al Ponte
agponte@infosolvllc.com

Adian009 06-04-2004 09:59 PM

Mod That Auto-Checks All Options
 
I have a mod that I developed that allows you to specify whether an option is "Required", "Verified" or "None" by using a drop-down box next to each option.

If an option is "Required" then the customer cannot add to cart if the field is blank, "Verified" asks the user to confirm the blank entry before adding to the cart, finally "None" is not validated at all.

Email me if you are interested....

Al Ponte
agponte@infosolvllc.com

PhilJ 06-05-2004 04:23 AM

Many thanks Adian009 :wink:

Code:

if (product_option('Product Option').value == '')
{ alert('You must enter an option');
return false;
}
else {return true;}


You can still bypass it, by pressing Enter in the product option field, so I disabled the Enter key...

Add this script to the top of skin1/customer/main/product.tpl

Code:

{literal}
<script type="text/javascript">
function handleEnter (field, event) {
                var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
                if (keyCode == 13) {
                        var i;
                        for (i = 0; i < field.form.elements.length; i++)
                                if (field == field.form.elements[i])
                                        break;
                        i = (i + 1) % field.form.elements.length;
                        field.form.elements[i].focus();
                        return false;
                }
                else
                return true;
        }     

</script>
{/literal}


then find
/skin1/modules/Product_Options/customer_options.tpl

change
Code:

<input type=text name="product_options[{$product_options[product_option].optclass}]" size=12>

to

Code:

<input type=text name="product_options[{$product_options[product_option].optclass}]" onkeypress="return handleEnter(this, event)" size=12>


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

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