簡體   English   中英

$ _POST變量未通過表單傳遞

[英]$_POST variables not passed by form

我正在使用PHP在App Engine上托管一個簡單的聯系表單,試圖將$ _POST變量從表單傳遞到發送電子郵件的PHP腳本。 正如我從日志中看到的那樣,$ _POST變量似乎沒有通過,並且我很難理解為什么...因此,希望對此有另一雙眼睛...謝謝。 以下是(簡化)代碼的各個部分:

在根目錄的index.html中:

<form method="post" action="#" id="contactform">
<div>
<label for="email">Enter your email</label>
<input type="text" class="input-field" id="email" name="email" value="">
</div>
<a id="button-send" href="#" title="Send Email" class="button" style="width:100%;">Send E-Mail</a>
<div id="success">Your message has been sent successfully!</div>
<div id="error">Unable to send your message, please try later.</div>
</form>

PHP文件,也位於根目錄:

<?php 
$send_email_to = "test@test.com";
$email_subject = "Email subject line";

function send_email($email,$email_message)
{
// using AppEngine's mail function here
}

function validate($email,$message)
{
// a simple validation function
}

if(isset($_POST['email'])) { 
$email = $_POST['email']; // this doesn't seem to work
}
else
{$email = "email@email.com";} // did this to confirm the $_POST didn't seem to be passed

$return_array = validate($email,$message);

if($return_array['success'] == '1')
{
send_email(,$email,$message);
}

header('Content-type: text/json');
echo json_encode($return_array);
die();
?>

以及控制錯誤消息的javascript:

$('#button-send').click(function(event){
    $('#button-send').html('Sending message...');
    event.preventDefault();

    $('html, body').scrollTo( $('#contact'), 'fast' );
    $.ajax({
        type: 'POST',
        url: 'send_form_email.php',
        data: $('#contact_form').serialize(),
        success: function(html) {
            if(html.success == '1')
            {
                $('#button-send').html('Send message');
                $('#success').show();
            }
            else
            {
                $('#button-send').html('Send message');
                $('#error').show();
            }                   
        },
        error: function(){
            $('#button-send').html('Send message');
            $('#error').show();
        }
    });

如果這與App Engine有關,則我的app.yaml如下所示:

- url: /js
  static_dir: js

- url: /send_form_email.php*
  script: send_form_email.php

- url: .*
  script: index.html

再次非常感謝–我還將完整的代碼放在了Google雲端硬盤中: https : //drive.google.com/file/d/0B4yzSrEzbZ5jbk1oc2RWb2xSRWM/edit?usp=sharing

您正在嘗試序列化#contact_form但具有id="contactform"

JSON的MIME類型是application/json ,不是text/json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM