想要读出修复输入隐藏标记

时间:2018-06-10 10:18:29

标签: jquery css input utf-8 hidden

我必须更改我的jquery或css以读取输入隐藏标记的修复值?我有不同的网站使用相同的“表单”,并想要读出用户来自哪个网站。

另一个问题是,我如何才能正确整合utf-8 charset。它仍然无法正常工作。

我的jquery

/ *联系表格

var submitContact = $('#submit-message'),
    message = $('#msg');

submitContact.on('click', function(e){
    e.preventDefault();

    var $this = $(this);

    $.ajax({
        type: "POST",
        url: 'send2.php',
        dataType: 'json',
        cache: false,
        data: $('#contact-form').serialize(),
        success: function(data) {

            if(data.info !== 'error'){
                $this.parents('form').find('input[type=text],input[type=email],input[type=checkbox],textarea,select').filter(':visible').val('');
                message.hide().removeClass('success').removeClass('error').addClass('success').html(data.msg).fadeIn('slow').delay(5000).fadeOut('slow');
            } else {
                message.hide().removeClass('success').removeClass('error').addClass('error').html(data.msg).fadeIn('slow').delay(5000).fadeOut('slow');
            }
        }
    });
});

我的css

<?php 
if($_POST) {

    $to = "question@sample.com"; // Your email here
    $subject = 'Question'; // Subject message here

}

//Send mail function
function send_mail($to,$subject,$message,$headers){
    if(@mail($to,$subject,$message,$headers)){
        echo json_encode(array('info' => 'success', 'msg' => "Message send."));
    } else {
        echo json_encode(array('info' => 'error', 'msg' => "Message not send."));
    }
}

//Check if $_POST vars are set
if(!isset($_POST['firstname']) || !isset($_POST['lastname'])  ||  !isset($_POST['telefon']) || !isset($_POST['email'])   || !isset($_POST['message'])  )
{
    echo json_encode(array('info' => 'error', 'msg' => 'Fill out all fields.'));
}

$check1 = isset($_POST['check1']) ? true : false;
$check2 = isset($_POST['check2']) ? true : false;




//Sanitize input data, remove all illegal characters    
$firstname    = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
$lastname    = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);

$telefon    = filter_var($_POST['telefon'], FILTER_SANITIZE_STRING);
$email    = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);


$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);



//Validation
if($firstname == '') {
    echo json_encode(array('info' => 'error', 'msg' => "Do something"));
    exit();
}
if($lastname == '') {
    echo json_encode(array('info' => 'error', 'msg' => "Do something"));
    exit();
}

if($telefon == '') {
    echo json_encode(array('info' => 'error', 'msg' => "Do something"));
    exit();
}

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
    echo json_encode(array('info' => 'error', 'msg' => "Do something"));
    exit();
}
if($message == ''){
    echo json_encode(array('info' => 'error', 'msg' => "Do something"));
    exit();
}
if($check1 == false) {
    echo json_encode(array('info' => 'error', 'msg' => "Click this."));
    exit();
}
if($check2 == false) {
    echo json_encode(array('info' => 'error', 'msg' => "Click this"));
    exit();
}


//Send Mail



$headers = 'From: ' . $email .''. "\r\n".
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

send_mail($to, $subject,  $message . "\r\n\n"  .'Vorname: '.$firstname. "\r\n"  .'Nachname: '.$lastname. "\r\n"  .'sideID: '.$sideID. "\r\n"   .'Telefon: '.$telefon. "\r\n" .'Datenschutz: '.$check1. "\r\n" .'Widerruf: '.$check2.  "\r\n" .'Email: '.$email, $headers);

&GT;

我的HTML

<form id="contact-form" accept-charset="utf-8" action="" method="POST">

<div class="row contact-row">
            <div class="col-md-6 contact-name">
              <input type="text" id="firstname" name="firstname" placeholder="Vorname *" required>
            </div>
            <div class="col-md-6 col-sm-6 col-xs-6 contact-name">
              <input type="text" id="lastname" name="lastname" placeholder="Nachname *" required>
            </div>
            </div>

          <div class="row contact-row">
            <div class="col-md-6 col-sm-6 col-xs-6 contact-name">
              <input name="telefon" id="telefon" type="text" placeholder="Telefon *" required>
            </div>
            <div class="col-md-6 col-sm-6 col-xs-6 contact-email">
              <input name="email" id="email" type="email" placeholder="E-Mail *" required>
            </div>
          </div>

          *<input name="sideID" id="sideID" type="hidden" value="1402">*
          <textarea name="message" id="message" placeholder="Your message to us</textarea>


                            <div class="col-md-12 col-sm-12 col-xs-12 mb-30">
            <h6>Notice</h6>
            <ul class="checkboxes">
              <li>
                <input type="checkbox" class="input-checkbox" name="check1" id="check1"  required>
                <label for="check1">*&nbsp;&nbsp;Read this.</label>
              </li>
              <li>
                <input type="checkbox" class="input-checkbox" name="check2" id="check2"  required>
                <label for="check2">*&nbsp;&nbsp;Notice this.</label>
              </li>

            </ul>
          </div>

          <input type="submit" class="btn btn-lg btn-submit" value="Send message" id="submit-message">
          <div id="msg" class="message"></div>
        </form>

0 个答案:

没有答案