Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

I don't get it, textarea php output

Featured Replies

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

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 by Spitfire

Is this a typo in your code or just on this post?

if (!IsSet($_POST["question"]))

Should be

if (!isset($_POST["question"]))

  • Author

uhrm that doesn't matter anyway.......

 

Even without that isset function I get undefined index...

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 by CSN-UK

  • 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 by kensha

@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 by CSN-UK

  • 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 by kensha

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:


  1.  
  2. Open the page; notice how you have "Question has not been set".
  3. Enter something into each field of the form and press submit, It will then be echo'd as desired.
  4. 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 by CSN-UK

  • 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?

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 by CSN-UK

  • Author

Alright, that clears things up, thanks.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.