bbmak Posted August 24, 2012 Share Posted August 24, 2012 I have this validation of my form. However, the empty function treats all 0 as empty. Are there anyway to make 0 as not an empty value? if (empty($item_name) || empty($item_link) || empty($item_price)) { $errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.'; } else { $validate = new validate(); if(!$validate->validateURL($item_link)) { $errors[] = 'This is not a URL.'; } if (!is_numeric($item_price)) { $errors[] = 'Item Price Must be a number.'; } } Quote Link to comment Share on other sites More sharing options...
aliento Posted August 24, 2012 Share Posted August 24, 2012 or you can use $item_name=='' if (!(isset($item_name)) || !(isset($item_link)) || !(isset($item_price))) { $errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.'; } else { $validate = new validate(); if(!$validate->validateURL($item_link)) { $errors[] = 'This is not a URL.'; } if (!is_numeric($item_price)) { $errors[] = 'Item Price Must be a number.'; } } Quote Link to comment Share on other sites More sharing options...
MMDE Posted August 24, 2012 Share Posted August 24, 2012 print_r($_POST); or print_r($_GET); depends on the method specified in the form. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 24, 2012 Share Posted August 24, 2012 Do you want to allow 0s? Use strlen() Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 25, 2012 Share Posted August 25, 2012 Alliento has the best idea but use logical == to compare for empty. if ($item_name=='' || $item_link=='' || $item_price=='') { $errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.'; } else { $validate = new validate(); if(!$validate->validateURL($item_link)) { $errors[] = 'This is not a URL.'; } if (!is_numeric($item_price)) { $errors[] = 'Item Price Must be a number.'; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.