1

Following this post I have created this html inside a form:

...
<input type="text" name="setValues[cardExpiration]" id="card_expiry" class="input-small" value="1222">
<input type="text" name="setValues[ipAddress]" id="ip" value="24.37.246.194">
...

After the form is submitted, inside the $_POST array I see this multi dimensional array as expected: enter image description here

When I try to retrieve the value, something is happening:

$email = (isset($_POST["setValues"])?$_POST["setValues"]["email"]:FALSE);//Gives NULL

$email = (isset($_POST["setValues"])?$_POST["setValues"]["'email'"]:FALSE);//Gives the email filled in the form.

The point here is the ' key ' single quotes in the array key. It is being part of the key.

This is why $_POST["setValues"]["'email'"] works and $_POST["setValues"]["email"] don't.

So what should I do to get the array without quotes inside the key? How to properly setup it inside the input attribute?

This is the var_dump():

echo '<pre>';
    var_dump($_POST);
echo '</pre>';

enter image description here

IgorAlves
  • 5,086
  • 10
  • 52
  • 83
  • `$_POST["setValues"]["'email'"]` does not work, and `$_POST["setValues"]["email"]` does, as expected - see answer below. – lovelace Oct 23 '17 at 21:05

1 Answers1

0

Getting the expected behavior with the following:

<form method='POST'>
<input type="text" name="setValues[cardExpiration]" id="card_expiry" class="input-small" value="1222">
<input type="text" name="setValues[ipAddress]" id="ip" value="24.37.246.194">
<input type="email" name="setValues[email]" id="email" value="test@testmail.com">
<input type='submit' name='submit'>
</form>

<?php
if(isset($_POST['submit'])) {

/* show $_POST array */
echo '<pre>';
var_dump($_POST);
echo '</pre>';

$email = (isset($_POST["setValues"])?$_POST["setValues"]["email"]:FALSE);
echo $email; /* output: test@testmail.com */

$email = (isset($_POST["setValues"])?$_POST["setValues"]["'email'"]:FALSE);
echo $email; /* output: Notice: Undefined index: 'email' */
}
?>
lovelace
  • 1,195
  • 1
  • 7
  • 10