Submission of html form data


Good morning. I have a form that collects the data that is inserted and sent to a page in php in charge of making the shipment. The whole process is done well, except for the field referring to a select, whose field is not sent, even in white. I attach the code fragment:

 <form id="Formulario" name="formucontacto" action="envio.php">

                    <input type="text" id='nombre' name="nombre" placeholder="Introduce tu nombre..." required>
                    <input id='mail' name="mail" type = 'email' placeholder="Introduce tu correo electrónico" required>
                    <input id='Telefono' name="telefono" type = 'text' placeholder="Introduce tu telefono" required>
                    <select id="producto" name='producto' required>
                        <option value="" default>-- Selecciona tu producto --</option>
                        <option value="1">Producto1</option>
                        <option value="2">Producto2</option>
                        <option value="3">Producto3</option>
                        <option value="4">Producto4</option>
                        <option value="5">Producto5</option>
                        <option value="6">Otro...</option>

                   <input type="submit" onclick="if (validarcontacto()) this.form.submit()" id="solicitar" value="SOLICITAR"/>                    

By clicking on the button REQUEST a function is called where it is verified if the fields are empty or not, and if everything is correct, the form is sent to a php page with the following function at the beginning of it:

foreach($_REQUEST as $campo=>$valor){
  .$texto .= $campo.": ".$valor."\n\n"; 
$cabeceras = 'From: $config_email'."\r\n";
$cabeceras .= 'MIME-Version: 1.0'."\r\n";
$cabeceras .= 'Content-type: text/html; charset=utf8'."\r\n";
$cabeceras .= 'Bcc: [email protected]' . "\r\n";

//Envio de mail
mail("[email protected]", "Mensaje desde la Web", nl2br($texto), $cabeceras);  

As I said before, it works correctly, but the select field does not send it to me, I have tried giving it a name attribute like the rest, but everything is the same. I appreciate all help, thank you very much.

asked by AntonioMP87 09.05.2017 в 11:55

2 answers


I have tried the form exactly as you have it in your question, and there is no problem, when doing this post it is sent:


As you can see at the end, the product is posted well.

What could be the problem?

I recently answered the following question: Is it correct to use the same id and name in the input of an html form?

If you are using your form in an Internet Explorer version lower than v. 10, or for any other reason ... Javascript can not distinguish between id and name if those attributes have the same value, precisely what happens in your case.

That may be a possible cause of why producto is not being posted, in your case.

You can try putting a id other than the tag , to debug that possibility, that is:

 <select id="producto_id" name="producto" required>

It would be interesting to try and tell the type of browser you have, because it is the only reason why I see you could be failing.

Note: When reading this in your question:

I've tried giving it a name attribute like the rest, but everything is the same.

I just want to point out that the data sent by _$POST are retrieved by the attribute name , not by the attribute id , so that an element that has not indicated the attribute name can not be recovered in _$POST .

P.D. On the other hand, uniformity is good when you write the attributes of your labels. I say this because sometimes you use '...' and other times you use "..." ,

for example:

<input type="text" id='nombre' name="nombre" placeholder="Introduce tu nombre..." required>
                      ^      ^ 
                     ¿por qué no usas " " también ahí?

It is convenient that you decide on one of the two and that you write everything uniformly.

answered by 09.05.2017 / 16:08

Try to change:

<option value="" default>-- Selecciona tu producto --</option>


<option value="" selected>-- Selecciona tu producto --</option>
//               ^^^^^^^^

According to the w3schools documentation, the default attribute does not exist in that context: Link

I have also seen that you are missing the method attribute in the form tag, without this attribute the form will not send anything by POST , add to your form tag the method="POST" attribute

It would be like this:

<form id="Formulario" name="formucontacto" method="POST" action="envio.php">
answered by 09.05.2017 в 12:41