I have this page:
<?php
for($i=1; $i<=3; $i++){
$until_he.$i = htmlentities($_POST['until'.$i])
}
?>
<form action="" method...>
<?php
for($i=1; $i<=3; $i++){
...
print '<input name="until'.$i.'" id="until'.$i.'" class="textinput" value="'.$until_he.$i.'" type="date" min="'.date("Y-m-d").'"/>';
...
}
?>
...
Now:
$until_he
has content only once the form is posted, otherwise it's empty. On the other hand
$i
is already defined. So as I load the page I get values 1, 2, 3 on the fields.
I'd like to get values on the files only once the user post the forum. As I load the page the fields should be empty.
Thank you
Try this:
<?php
for($i=1; $i<=3; $i++){
$until_he.$i = htmlentities($_POST['until'.$i]);
$fieldValue = (trim($until_he.$i)==$i)?"":$until_he;
...
print '<input name="until'.$i.'"
id="until'.$i.'"
class="textinput"
value="'.$fieldValue.'"
type="date" min="'.date("Y-m-d").'"/>';
...
}
?>
Depends on what you want to accomplish and other code you have. In your example, you should use isset($until_he) which doesn't generate a warning if the variable is not set. Also, it works in the case the variable $until_he is set but empty. However, it will fail if you initialize $until_he to an empty value beforehand.