Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding an item at 0.00 - can I stop it with javascript?


spectral

Recommended Posts

Posted

On admin/categories.php I have the following:

<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
 {
 if (value==null||value=="")
   {
   alert(alerttxt);return false;
   }
 else
   {
   return true;
   }
 }
}

function validate_form(thisform)
{
with (thisform)
 {
 if (validate_required(products_price,"Price cannot be left blank!")==false)
 {email.focus();return true;}
 }
}
</script>

 

above:

</head>

 

For the form action I have the following:

echo tep_draw_form('new_product', FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : '') . '&action=new_product_preview" onsubmit="return validate_form(this)"', 'post', 'enctype="multipart/form-data"');

 

When I leave the products_price field blank, I get the javascript alert (as expected) but the item still proceeds to get added to the database.

 

Ideally, the form wouldn't submit but would sit there until I add a price.

Not sure what I may be missing here. Can anyone offer insight?

Posted

 

When I leave the products_price field blank, I get the javascript alert (as expected) but the item still proceeds to get added to the database.

 

Ideally, the form wouldn't submit but would sit there until I add a price.

Not sure what I may be missing here. Can anyone offer insight?

 

When the validation is returning false you are focusing on email and returning true, therefore the form is still submitting.

Posted

Too hasty with my cut & paste, I suppose!

 

I've changed it to the following:

<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
 {
 if (value==null||value=="")
   {
   alert(alerttxt);return false;
   }
 else
   {
   return true;
   }
 }
}

function validate_form(thisform)
{
with (thisform)
 {
 if (validate_required(products_price,"Price cannot be left blank!")==false)
 {products_price.focus();return true;}
 }
}
</script>

 

....same result.

Posted

Too hasty with my cut & paste, I suppose!

 

I've changed it to the following:

<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
 {
 if (value==null||value=="")
   {
   alert(alerttxt);return false;
   }
 else
   {
   return true;
   }
 }
}

function validate_form(thisform)
{
with (thisform)
 {
 if (validate_required(products_price,"Price cannot be left blank!")==false)
 {products_price.focus();return true;}
 }
}
</script>

 

....same result.

 

you are still returning true, try ..

 

function validate_form(thisform)
{
with (thisform)
 {
   if (validate_required(products_price,"Price cannot be left blank!\nAfter the page reloads, please fix this.")==false)
   {
     products_price.focus();
     return false;
   } else return true;
 }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...