Note that there are some explanatory texts on larger screens.

plurals
  1. POBlank input field gives previous default value in $_POST
    primarykey
    data
    text
    <p>I am new here so hope I am respecting the protocol ;-)</p> <p>Here's a simple issue that for some reason I cannot solve.</p> <p>I have a form with post action calling a php file, and several text input fields with default values set. Example:</p> <pre><code>&lt;form class="form-horizontal" method="post" action="profile.php"&gt; &lt;input type="text" class="input-xlarge" id="q-2-Address" name="q-2-Address" value="Park Avenue"&gt; &lt;button type="submit" class="btn btn-primary"&gt;Save changes&lt;/button&gt; &lt;/form&gt; </code></pre> <p>If I submit the form leaving the default value unchanged, <code>$_POST['q-2-Address']</code> contains the default "Park Avenue" as expected.</p> <p>If I try to change the value in the input text field (ex: to "Madison Avenue") I can see the result in <code>$_POST['q-2-Address']</code> which gets set to "Madison Avenue", as expected.</p> <p>But if I try to clear the value by removing all text, the <code>$_POST['q-2-Address']</code> is NOT blank and in fact goes back to containing the default value set initially "Park Avenue".</p> <p>So if I want to update a form by replacing previously filled fields with blanks, this seems to be impossible, nor is it possible to detect that the field has been cleared. I tried testing using empty() but of course it gives a false result, <code>$_POST</code> contains the default value so is not empty even though the text field is empty.</p> <p>Short of my entering something like a single space, I see no way of actually clearing a field.</p> <p>It is a trivial thing but maybe somebody knows more about this.</p> <p>TIA</p> <p>Mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload