1

我正在使用 codeignitor 安装一个简单的注册表单。

电子邮件正在发送,但表单数据未显示在电子邮件中。数据通过 AJAX 发送到欢迎文件并点击公共函数 signup()。

它正在访问文件,因为电子邮件正在发送,但没有表单数据。

形式:

<div class="form">
                                <form ONSUBMIT="return checkRequired(this)" method="post" id="subForm">
                                    <div class="signupbox">
                                         <span class="label"><label for="FirstName">First Name:</label></span>
                                            <span><input type="text" name="firstname" id="firstName" size="25" class="required" /></span>
                                    </div>
                                    <div class="signupbox">
                                        <span class="label"><label for="LastName">Last Name:</label></span>
                                            <span><input type="text" name="lastname" id="lastName" size="25" class="required" /></span>
                                    </div>
                                    <div class="signupbox">
                                        <span class="label"><label for="email">Email:</label></span>
                                            <span><input type="text" name="email" id="email" size="25" class="required" /></span>
                                    </div>
                                    <div class="signupbox">
                                        <span class="label"><label for="Company">Company:</label></span>
                                            <span><input type="text" name="company" id="company" size="25" /></span>
                                    </div>
                                    <div class="signupbox">
                                        <span class="label"><label for="Comments">Tell us about yourself:</label></span>
                                            <span><textarea name="comments" id="comments" cols="45" rows="5" ></textarea></span>
                                    </div>
                                    <div>
                                        <span class="button"><input type="submit" value="Sign Up" id="ajaxsubmit" /></span>
                                    </div>
                                </form>
                            </div>  

注册.js:

$(document).ready(function(){

$('#ajaxsubmit').click(function(){


    var formobj = new Object();

    formobj.firstName = $('#firstName').val();
    formobj.lastName = $('#lastName').val();
    formobj.email = $('#email').val();
    formobj.company = $('#company').val();
    formobj.comments = $('#comments').val();







    //alert(JSON.stringify(formobj));


            $.ajax({
              type: 'post',
              url: 'http://www.alloi.co/signup',
              dataType: 'json',
              data: JSON.stringify(formobj) 
              });
    })


});

欢迎.php:

public function signup()
{


    $fname = $this->input->post('firstname', TRUE);
    $lname = $this->input->post('lastname', TRUE);
    $email = $this->input->post('email', TRUE);
    $company = $this->input->post('company', TRUE);
    $comments = $this->input->post('comments', TRUE);
    $headers = "MIME-Version: 1.0";
    $headers = "Content-type: text/plain; charset=iso-8859-1";
    $headers = "X-Mailer: PHP/".phpversion();

    $message = $fname." ".$lname. " has signed up for COMPANY.\n\nYou can reach ".$fname." at ".$email."\n\n".$fname." works for ".$company. "\n\n \n\n" .$comments;        

    mail("someone@email.com", 'Alloi Account Sign-up', $message, $headers);
}

电子邮件:

已注册 ALLOI。

您可以到达

效劳于

我敢肯定这很简单,但我仍在学习。我做错了什么不发送表单数据?

非常感谢您,

史蒂文

4

1 回答 1

1

您在帖子中发送 json,但您尝试在服务器端以 application/x-www-form-urlencoded 的形式读取数据,如果您想在服务器端按原样读取数据,只需按formobj原样传递

$.ajax({
    type: 'post',
    url: 'http://www.alloi.co/signup',
    data: formobj
});
于 2013-04-18T02:09:28.217 回答