How do I pass an array in HTML attributes and not show single quotes?

1

Following this post I've created the following html passing arrays as an input element attribute:

...
<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 we will have the following multi-dimensional array inside $_POST :

Perceivewithvar_dump()thekeysoftheinternalarray:

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

Whenwetrytoretrievethevaluesthisiswhathappens:

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

$email = (isset($_POST["setValues"])?$_POST["setValues"]["'email'"]:FALSE);//Retorna o e-mail preenchido no formulário

The center point here is the ' key ' tag that is being created within the array key.

That's why $_POST["setValues"]["'email'"] works and $_POST["setValues"]["email"] does not work, returns NULL.

So my question is how could we create this array within the input attribute without these single quotes appearing in the key?

    
asked by anonymous 24.10.2017 / 14:56

1 answer

1

I tested it here and it works normally.

When you submit a form this way:

            <div>
                    <label>Nome:</label>
                    <input type="text" name="form[nome]">
                </div>

                <div>
                    <label>E-mail:</label>
                    <input type="text" name="form[email]">
                </div>

                <div>
                    <label>Telefone/Whatsapp:</label>
                    <input type="text" name="form[telefone]">
                </div>
            </div>

php will normally receive:

var_dump($_POST["form"]["nome"]);

// irá exibir
string(87) "Quo molestias deserunt voluptas fuga Molestiae animi vel aliquip elit quam ipsum soluta"
    
22.09.2018 / 05:27