McNavy McNavy - 11 months ago 59
HTML Question

Check if input is not empty and exist - PHP

I need to check if several tags are "not empty". For this I use:

<input id="designation" type="text" size="12" disabled="disabled" />

Then, I need to place several of
<input ...>
in a table. All of this is created in HTML. I need to check if any of the tags are empty.

$erreurs = array();
// Check if the tag is not empty

if((empty($_POST['CodetERDF']))) {
$erreurs[] = 'Veuillez renseigner le codet ERDF.';

echo 'Veuillez renseigner le codet ERDF.';

But my code doesn't seem to work and I don't understand why.

Answer Source

Disabled inputs are not posted to the server, so they will never appear in $_POST.

The same applies to inputs without a name attribute as it is the name attribute that defines they key in $_POST.

Alternatives are making them readonly, hidden or simply setting the value in a session variable / keeping it on the server.