Recover POST when field name has score

Asked

Viewed 37 times

0

I’m creating a form that has a field that way:

<form name="form1">
  <select name="cmbitens.99">
    <option value="item 1">item1</option>
    <option value="item 2">item2</option>
    <option value="item 3">item3</option>
  </select>
</form>

Man name in the form has "." (It needs to be this way because I am using, that same name in a Google application) when I load this field in PHP it does not inform me the value of the field.

<?php
$valor = $_POST['cmbitens.99'];
echo $valor;

?>

I’m not getting around this obstacle, someone can help me ?

  • But you’re not using POST on your form. There was no missing one method="POST" there?

  • I just gave an abbreviated here not to get too long the text, but in my code has the Post method. <form name="Form1" method="post" > <select name="cmbitens.99"> <option value="item 1">item1</option> <option value="item 2">item2</option> <option value="item 3">item3</option> </select> </form>

  • And what is the result of var_dump($_POST)?

  • var_dump gave the solution tbm, I just needed to exchange "." for "_" in my php... Thanks

1 answer

3


To documentation of PHP says that points (.) and spaces of a variable are converted to underline (_).

Dots and Spaces in variable Names are converted to underscores. For example <input name="a.b" /> Becomes $_REQUEST["a_b"].

Then the variable access must occur as follows:

<?php

$valor = $_POST['cmbitens_99'];
echo $valor;

?>

Try to use the hyphen (-) or underline (_) instead of the point (.), as this will avoid confusion when using CSS and/or JS.

<div id="user.name"></div>


/*
 * Está buscando um elemento que que contenha o id igual a "user"
 * e que tenha a classe igual a "name".
 */
const name = document.querySelector('#user.name');
  • It worked great now... Thank you !!

  • Give nothing! I’m happy to help you.

  • Practical behaviour: https://repl.it/@acwoss/sopt-Question-400307

Browser other questions tagged

You are not signed in. Login or sign up in order to post.