1
I have the following variable input in my form:
<input class="caption_text" type="text" name="caption[]" required/>
That I create dynamically with JS.
After submitting I test the following:
$mycaption = \filter_input_array(\INPUT_POST, 'caption');
foreach ($mycaption as $eachInput) {
echo "Caption " . $eachInput . "<br>";
}
I found that the above code did not work.
However, unsaying $_POST, so:
$cpost = $_POST["caption"];
foreach ($cpost as $eachInput) {
echo "Caption " . $count. " - " . $eachInput . "<br>";
}
Then it works as expected.
Can someone please tell me why the first approach doesn’t work?
What are those inverted bars in your code?
– Bacco
Is using the
filter_input_array
and having it validate what ? Of course the return will benull
, try adding some expression to validate what you expect to receive in this field.– William Novak
Hi, I don’t want to validate anything, just get the variable submitted. It is recommended to no longer use the $_POST direct global variable and yes through a filter_input.
– user1818765