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)
-   -   Validation script to check if custom text field has been filled (https://forum.x-cart.com/showthread.php?t=41200)

Warwick 07-18-2008 05:50 AM

Validation script to check if custom text field has been filled
 
I'm trying to get a validation script at the product options which will check if a custom text field (one of the options) has been filled in. So basically that it becomes mandatory when ordering the product, any way to do this?

Warwick 08-16-2008 12:48 PM

Re: Validation script to check if custom text field has been filled
 
Is there anybody who can help me with this?

Ene 08-17-2008 08:48 AM

Re: Validation script to check if custom text field has been filled
 
http://www.x-cart.com/xcart_manual/online/?product_options3.htm

Example:
HTML Code:

var value = product_option_value("Color");
var value2 = product_option_value("Size");
if (value !== false && value == "Blue" && value2 !== false && value2 == 'XL') {
    alert("Sorry, the combination of Blue and XL is not available currently. Please check back later");
    return false;
}


Warwick 08-18-2008 06:14 AM

Re: Validation script to check if custom text field has been filled
 
Thanks for the headsup Eugene but I think this will not work in my case; I have a custom text field as product option and the customer needs to fill it in with a url

Warwick 08-18-2008 06:18 AM

Re: Validation script to check if custom text field has been filled
 
The name of the product option is 'url'

Would this be the solution":
Code:

var value = product_option_value("url");
if (value !== false ) {
    alert("Sorry, you should enter an url");
    return false;


Ene 08-18-2008 06:22 AM

Re: Validation script to check if custom text field has been filled
 
Use this code:

PHP Code:

var value product_option_value("url");
if (
value == '' ) {
    
alert("Sorry, Sorry, you should enter an url");
    return 
false;



Victor D 08-18-2008 06:23 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

var value = product_option_value("url");
if (value !== false ) {
alert("Sorry, you should enter an url");
return false;
Code:

if (value == false ) {
is more correct I think

Warwick 08-18-2008 06:32 AM

Re: Validation script to check if custom text field has been filled
 
So what should I use?

Code:

if (value == false ) {

or

Code:

if (value == '' ) {


And is there a way to let the script check if it is an url?

btw when using the 'Buy now' button the script is bypassed :(

Victor D 08-18-2008 07:22 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

Originally Posted by Warwick
So what should I use?
Code:

if (value == false ) {

or
Code:

if (value == '' ) {


It seems to me two variants are possible.

Quote:

Originally Posted by Warwick
So what should I use?
And is there a way to let the script check if it is an url?
btw when using the 'Buy now' button the script is bypassed :(


It is highly depend on what are you mean by "correct URL".

Code:

var value = product_option_value("url");
if (value == false ) {
    alert("Sorry, you should enter an url");
    return false;
}

Should work. Code posted above by Ene is OK too. See if your custom field's name is exactly matching 'url' (including case)

Warwick 08-18-2008 07:45 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

It is highly depend on what are you mean by "correct URL".

Well if it is a valuable url i.e. something.something.tld

Victor D 08-18-2008 08:15 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

Originally Posted by Warwick
Well if it is a valuable url i.e. something.something.tld

So something like "domain.tld" or "domain.domain.tld/smth.php" is considering to be an invalid URL and no matter if 'http://' is present?
Try something like this:

Code:

var value = product_option_value("url");
if (value == false ) {
    alert("Sorry, you should enter an url");
    return false;
}
var re =  new RegExp(/^(http:\/\/)?[^\.]+\.[^\.]+\.[^\.]+$/i);
if (! re.test(value)) {
    alert("Url you provided seems to be incorrect");
  return false;
}


Warwick 08-18-2008 08:22 AM

Re: Validation script to check if custom text field has been filled
 
You're the man! Thanks Victor :)

One little thing to make things even better:

Change
alert("Url you provided seems to be incorrect");

Into
alert("Url you provided seems to be incorrect, a correct Url would be www.mydomain.com");

Victor D 08-18-2008 09:36 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

Originally Posted by Warwick
You're the man!

I wish it were so, but i forgot about slashes.
So "domain.com/page.php" will pass this test.

so it would be better replace
Code:

var re =  new RegExp(/^(http:\/\/)?[^\.]+\.[^\.]+\.[^\.]+$/i);

with
Code:

var re =  new RegExp(/^(http:\/\/)?[^\.\/]+\.[^\.\/]+\.[^\.]+$/i);

Warwick 08-18-2008 02:19 PM

Re: Validation script to check if custom text field has been filled
 
Still the man :)

But when you enter www.mydomain.com/shop it is also accepted

Ene 08-18-2008 10:56 PM

Re: Validation script to check if custom text field has been filled
 
Quote:

btw when using the 'Buy now' button the script is bypassed

Enable the A customer using the "Buy now" button to order a product with product options must be redirected to the product details option.

Warwick 08-18-2008 11:08 PM

Re: Validation script to check if custom text field has been filled
 
Quote:

Originally Posted by Ene
Enable the A customer using the "Buy now" button to order a product with product options must be redirected to the product details option.


Smart thinking!
Why didn't I come up with that? :oops:

Thanks Eugene!

Warwick 08-18-2008 11:12 PM

Re: Validation script to check if custom text field has been filled
 
But hold on, you mean the 'Return customer to cart' option? I have that enabled already and this doesn't do the trick

Ene 08-18-2008 11:23 PM

Re: Validation script to check if custom text field has been filled
 
Quote:

But hold on, you mean the 'Return customer to cart' option?

No.
Open the 'General settings -> Product options' page.

Victor D 08-19-2008 12:19 AM

Re: Validation script to check if custom text field has been filled
 
Quote:

Originally Posted by Warwick
Still the man :)
But when you enter www.mydomain.com/shop it is also accepted


The answer is
Code:

      var re =  new RegExp(/^(http:\/\/)?[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/i);
8)
If you would like to know how it works, follow this link.
http://www.webreference.com/js/column5/


All times are GMT -8. The time now is 12:42 PM.

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