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.'; } } Link to comment https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/ 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.'; } } Link to comment https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/#findComment-1372042 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. Link to comment https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/#findComment-1372043 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() Link to comment https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/#findComment-1372105 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.'; } } Link to comment https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/#findComment-1372277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.