spectral Posted June 1, 2010 Posted June 1, 2010 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?
♥FWR Media Posted June 1, 2010 Posted June 1, 2010 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. Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
spectral Posted June 1, 2010 Author Posted June 1, 2010 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.
♥FWR Media Posted June 1, 2010 Posted June 1, 2010 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; } } Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
spectral Posted June 6, 2010 Author Posted June 6, 2010 Thank you very much, I finally see what I've been doing wrong thanks to your example. :)
Recommended Posts
Archived
This topic is now archived and is closed to further replies.