top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How Can I check for an empty field in a form?

0 votes
489 views
How Can I check for an empty field in a form?
posted Jul 10, 2014 by Karamjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

If you want to check whether a form field has a value or not, use the empty function

<?php $formvalue = "on"; if(empty($formvalue)) { echo "I am empty!"; } ?>
Don't get confused between isset and empty - the former just checks whether the variable is present or not but ignores any value it may or may not have.

answer Jul 11, 2014 by Rahul Mahajan
0 votes

ISSET checks the variable to see if it has been set, in other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a " ", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.

EMPTY checks to see if a variable is empty. Empty is interpreted as: " " (an empty string), 0 (0 as an integer), 0.0 (0 as a float), "0" (0 as a string), NULL, FALSE, array() (an empty array), and "$var;" (a variable declared, but without a value in a class.

answer Aug 16, 2014 by anonymous
Similar Questions
+1 vote

I'm trying to check if a cell is empty because when the parser reaches an empty cell it throws NoMethodError (undefined methodvalue' for nil:NilClass)`

This is what I was trying to do:

1.upto(inventory[0].sheet_data.size) do |line| @projectCode = inventory[0][line][1].value unless inventory[0][line][1].value.nil? @ProjectName = inventory[0][line][2].value unless inventory[0][line][2].value.nil? end

also tried

1.upto(inventory[0].sheet_data.size) do |line| @projectCode = inventory[0][line][1].value unless inventory[0][line][1].value.empty? @ProjectName = inventory[0][line][2].value unless inventory[0][line][2].value.empty? end

The cells with values have no issues, but when it reaches 2 empty rows below all data it throws this... Can anyone tell me how to do this?

...