donglian6625
2016-07-06 06:53
浏览 81
已采纳

Bootstrap 3表单和php - 电子邮件中同一行的多个输入

I've searched for hours but couldn't really find an answer about this.

What i would like to do is a large field and smaller field next to each other, eg. for an separated address or phone number, like Blackstreet 27 or 123 - 456789. It needs to be printed as one in the message i receive in my mailbox. Everything is going about two or multiple fields on a webpage, but not about the final result. Same name or id doesn't work.

<div class="row">
   <div class="col-xs-6">
     <div class="form-group">
        <label for="form_area">Area code *</label>
        <input id="form_area" maxlength="4" type="tel" name="area" class="form-control" placeholder="Area code required *" required="required" data-error="Your area code is required.">
        <div class="help-block with-errors"></div>
     </div>
   </div>
   <div class="col-xs-6">
     <div class="form-group">
        <label for="form_phone">Phone number *</label>
        <input id="form_phone" type="tel" pattern="^[_0-9]{1,}$" name="phone" class="form-control" placeholder="Phone number required *" required="required" placeholder="Your phone number is required.">
        <div class="help-block with-errors"></div>
      </div>
   </div>
</div>

EDIT: I'm sorry. I think it has something to do with the php file. The brings it all to break. When i remove it, it comes all to one line, and only some field have to come in one line.

code:

<?php

// configure
$from = 'emailadres'; 
$sendTo = 'emailadres';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'businessname' => 'Businessname', 'phone' => 'Phonenumber', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in email
$okMessage = 'I'll contact you asap!';
$errorMessage = 'Something went wrong. try again later';

// let's do the sending

try
{
$emailText = "You have new message from contact form
=============================
";

foreach ($_POST as $key => $value) {

    if (isset($fields[$key])) {
        $emailText .= "$fields[$key]: $value
";
    }
}

mail($sendTo, $subject, $emailText, "From: " . $from);

$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&  strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);

header('Content-Type: application/json');

echo $encoded;
}
else {
echo $responseArray['message'];
}

?>

3条回答 默认 最新

相关推荐 更多相似问题