November 28, 201114 yr I don't get it, textarea. <form method="post" action="post.php"> First Name:<br> <input type="text" size="30" name="FName"><br> Age:<br> <input type="text" size="30" name="Age"><br> Question:<br> <textarea name="question" rows="4" cols="27"></textarea><br> <input type="submit" value="submit" > </form> 1 stupid normal form and 1 stupid normal output: <?php if (!IsSet($_POST["question"])) { echo "Question has not been set"; } else { echo $_POST["FName"]; echo $_POST["Age"]; echo $_POST["question"]; } ?> In IE9 it works correctly but google chrome is doing stupid. Acoording to google chrome the question has not been set but acoording to IE9 it has been set..... Where did I go wrong?:s
November 28, 201114 yr I've never seen isset() written with capitals like that so I'd guess that is the problem if browsers aren't picking up on the if/else function. Change: IsSet() To: isset() Edited November 28, 201114 yr by Spitfire
November 28, 201114 yr Is this a typo in your code or just on this post? if (!IsSet($_POST["question"])) Should be if (!isset($_POST["question"]))
November 28, 201114 yr Author uhrm that doesn't matter anyway....... Even without that isset function I get undefined index...
November 28, 201114 yr Hi kensha, You need to be using "empty" rather than !isset, as on submitting your form the post variables will be created regardless of if they have any content. So on submitting an empty form you get: Array ( [FName] => [Age] => [question] => ) Which means your $_POST['question'] has been set, you can see this by adding print_r($_POST) to the top of your php statement. Edited November 28, 201114 yr by CSN-UK
November 28, 201114 yr Author @t CSN-UK show to me a script of your that aqtually works. 1 with a textarea. Cause all is working fine but not the textarea itself. The isset function is working correctly because it did output mine first echo. The problem only excist in google chrome and not IE9, Firefox or any other browser. Please check before you reply:) Edited November 28, 201114 yr by kensha
November 28, 201114 yr @t CSN-UK show to me a script of your that aqtually works. 1 with a textarea. Cause all is working fine but not the textarea itself. The isset function is working correctly because it did output mine first echo. The problem only excist in google chrome and not IE9, Firefox or any other browser. Please check before you reply:) This code functions correctly, your !isset will not function correctly after the form has been submitted in any browser as it always evaluates as the else or false option as the $_POST array is created whether the form is blank or otherwise, the only time this is not the case is when the page is loaded and the form has not been submitted. Isset checks for the existence of a variable or if it has been set as "NULL" not if the variable contains any value... you would use isset on a form mainly to check if a submit button has been pressed, use empty and !empty for other fields to check their values. <form method="post" action="post.php"> First Name:<br> <input type="text" size="30" name="FName"><br> Age:<br> <input type="text" size="30" name="Age"><br> Question:<br> <textarea name="question" rows="4" cols="27"></textarea><br> <input type="submit" value="submit" > </form> 1 stupid normal form and 1 stupid normal output: <?php print_r($_POST); // remove after testing... to demonstrate my point. if (empty($_POST["question"])) { echo "Question has not been set"; } else { echo $_POST["FName"]; echo $_POST["Age"]; echo $_POST["question"]; } ?> Edited November 28, 201114 yr by CSN-UK
November 28, 201114 yr Author Alright strange but what is the deal anyway with google chrome that only chrome need the empty function?:S Just don't get that part but thanks:). Edited November 28, 201114 yr by kensha
November 28, 201114 yr Alright strange but what is the deal anyway with google chrome that only chrome need the empty function?:S Just don't get that part but thanks:). Not a problem kensha, it is just understanding the two functions... it's not a chrome issue, the issue you had was the same for all browsers. Do the following with the old code as a test in all browsers: Open the page; notice how you have "Question has not been set". Enter something into each field of the form and press submit, It will then be echo'd as desired. Now still on the page press submit with nothing in any field. What you need to understand is that, once the page is loaded in step one, the $_POST array doesn't exist and thus !isset = true, hence you get your error message. In step two the $_POST array isset hence !isset = false and the message is shown. In step Three the $_POST array isset again but with no content so the $_POST Array is: ( [FName] => [Age] => [question] => ) and thus is true and will show no content. Note: The $_POST array is created everytime the form is submitted and thus !isset will always evaluate false. on the filp side empty checks the value of variables so: <?php $var = 0; // Evaluates to true because $var is empty if (empty($var)) { echo '$var is either 0, empty, or not set at all'; } // Evaluates as true because $var is set if (isset($var)) { echo '$var is set even though it is empty'; } ?> http://php.net/manual/en/function.empty.php This is a logic/code issue not a browser issue . Edited November 28, 201114 yr by CSN-UK
November 28, 201114 yr Author So tell me what's the aqtually difference between the isset and or empty function? They both check if the variable has been set yes or no. Is it perhaps isset checks the variable and empty checks the string of that variable?
November 28, 201114 yr So tell me what's the aqtually difference between the isset and or empty function? They both check if the variable has been set yes or no. Is it perhaps isset checks the variable and empty checks the string of that variable? That's right, they're not the same, I did put an example above... but basically isset checks for the existence of a variable so if you create a variable is would evaluate true, empty checks the existance of a value inside the variable. As such you could do this, although its not necessary: if(isset($_POST['question']) && !empty($_POST['question'])) which is: "does the variable exist and is it empty?" Edited November 28, 201114 yr by CSN-UK
Create an account or sign in to comment