Hi everyone, can you help me understand the logic why I can't access one of my the items in POST.
Here is my form:

<form action="insert2.php" method="POST">

<table border="0">               
            <tr>
                    <td width="40%"><b>Date:</b></td>
                    <td width="60%"> <input type='text' name="today" placeholder='<?php echo $today ?>' disabled='disabled'> </td>
            </tr>

            <tr>
                    <td width="40%"><b>User ID:</b></td>
                    <td width="60%"> 
                    <input type="text" name="userid" placeholder='<?php           
                    echo $_GET['message'];  
                    ?>'>
                    </td>
            </tr>
            </table>
            <br>
            <br>

                <font color="#990000" size="5px">    [ Choose the appropriate status, and edit the text field for the appropriate action ] </font>

                    <br>
                    <br>


            <table border="0">   
</FORM>

When I var_dump($_POST); it says that ["userid"]=> string(0) while in fact, it has a placeholder value and the value is displayed, but why I can't pass it?

Any help would be very much appreciated. Thankyou.

Dani AI

Generated

and are pointing in the right direction — the browser-visible placeholder is not a submitted value. Beyond that, the two common reasons a field shows text on-screen but arrives empty at PHP are (1) the text was only a placeholder (not the input’s value) and (2) the control was disabled, which prevents browser submission. The reliable fixes and a few troubleshooting checks follow.

If the value must come from the server and be submitted back, set it as the input’s value and escape it so quotes or HTML don’t break your markup:

<input type="text" name="userid"
  value="<?php echo htmlspecialchars(isset($_GET['message']) ? $_GET['message'] : '', ENT_QUOTES); ?>"
  readonly>

If you want the field visible but not editable and still submitted, use readonly (it is submitted). If you prefer a disabled-looking field, render it as disabled for display and add a hidden field with the same server-side value to actually send the data:

<input type="text" value="<?php echo htmlspecialchars($today, ENT_QUOTES); ?>" disabled>
<input type="hidden" name="today" value="<?php echo htmlspecialchars($today, ENT_QUOTES); ?>">

Quick debugging checklist:

  • View page source / use devtools to inspect the input’s actual value attribute (placeholder text will not appear there).
  • Confirm the input has a name and is inside the <form> that’s being submitted.
  • Make sure there’s a submit button and the form uses method="post".
  • Check for JavaScript that might clear fields on submit.

Security note: never echo raw GET/POST into attributes — always escape with htmlspecialchars(..., ENT_QUOTES) to avoid breaking attributes or introducing XSS. These steps will make the server receive the value you see in the browser.

Recommended Answers

All 2 Replies

the "placeholder" attribute (while not supported in all browsers) is a fancy way of giving a "hint" to the user as to what is supposed to go into the field. A place holder is usually something like "First Name" or "Phone Number" so when the user clicks the field, they know what they are supposed to type there. The value there ("First Name", etc..) is not the actual value of the field. If you want a default value passed in, you will need to set the value of the input, but then your placeholder would not be visibile unless the value is empty.

If you you want the GET to be passed to the form, instead of:
placeholder="<?echo ($_GET['message']);?>"
use
value="<?echo ($_GET['message']);?>"

Hope that helps!

Ryan

commented: Yes. It helps. A lot :) Thank you so much :) +1

You should use the value attribute of input type text

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.