vendredi 21 juillet 2017

Getting blank inputs from HTML form

So somebody asked me to look into their code because they were getting back empty values after emailing some input fields from PHP, but only a couple of them and everything looks fine to me, though I only have my iPhone right now so there's only so much I can do. Please in case anybody knows what's going on, it would be greatly appreciated if you could tell me or at least point me in the right direction.

<div class="col-md-6">
    <label>Su Mail *</label>
    <input type="email" value="" data-msg-required="Por favor ingrese su dirección de correo." data-msg-email="Ingrese un Mail válido." maxlength="100" class="form-control" name="email" id="email" required>
</div>

<div class="col-md-6">
    <label>Teléfono *</label>
    <input type="text" value="" data-msg-required="Por favor ingrese su teléfono." maxlength="100" class="form-control" name="fono" id="fono" required>
</div>

As you can see though both look the same, only the second one arrives empty from the examples above.

$name = $_POST['name'];
$email = $_POST['email'];
$fono = $_POST['fono'];
$inst = $_POST['inst'];
$mensaje = $_POST['message'];

$fields = array(
    0 => array(
        'text' => 'Name',
        'val' => $_POST['name']
    ),
    1 => array(
        'text' => 'Email address',
        'val' => $_POST['email']
    ),
    2 => array(
        'text' => 'Fono',
        'val' => $_POST['fono']
    ),
    3 => array(
        'text' => 'Institucion',
        'val' => $_POST['inst']
    ),
    4 => array(
        'text' => 'Message',
        'val' => $_POST['message']
    )
);

$message = '';

foreach($fields as $field) {
    $message .= $field['text'] . ': ' . htmlspecialchars($field['val'], ENT_QUOTES) . '<br>\n';
}

$headers = '';
$headers .= 'From: ' . $name . ' <' . $email . '>' . '\r\n';
$headers .= 'Reply-To: ' .  $email . '\r\n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=UTF-8\r\n';

if (mail($to, $subject, $message, $headers)){
    $arrResult = array ('response'=>'success');
} else{
    $arrResult = array ('response'=>'error');
}

The ones that don't work are "inst" and "fono"; they arrive blank while the other ones work just fine. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire