本文介绍了Phonegap原生应用程序,通过PHP邮件程序在活动服务器上提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过来自我的本机应用程序的实时服务器处理我的表单,而不离开页面。下面是我使用的表单,JQuery和PHP的代码,但是当我发送它,页面变为空白并将字符串放在URL栏。我可以得到一些帮助我的代码,请。我缩短了形式,使它更容易阅读,我有很多其他字段,以及。


$ b pre> < form action =http://mobile.koolantkoolers.com/mailer.phpmethod =get>
< div data-role =fieldcontain>
< label for =name>名称:< / label>
< input type =textname =nameid =namevalue =/>
< / div>
< div data-role =fieldcontain>
< label for =email>电子邮件:< / label>
< input type =emailname =emailid =emailvalue =/>
< / div>

< div data-role =fieldcontain>
< label for =company>公司:< / label>
< textarea cols =40rows =8name =companyid =company>< / textarea>
< / div>
< input type =buttononclick =submit()value =submitdata-icon =stardata-theme =b/>
< / div>
< / form>



JavaScript

  $ .post('http://mobile.koolantkoolers.com/mailer.php',{

//这些是表单的名称值

名称:$('name')。val(),
电子邮件:$('email')。 ).val()

// HTML函数

},函数(html){
//将HTML放入astring
var response = html;

// PHP完成并发送电子邮件
if(response ==success){
alert(Message sent!);
} else {

//错误回发
alert(对不起请填写所有字段!);
return false;
}
}

然后PHP

 <?php 

// VARS
$ Name = $ _ GET [name];
$ Email = $ _ GET [email];
$ Company = $ _ GET [company];
$ Headers =From:。 $ Email;

//验证
if(
$ name ==||
$ Email ==||
$ Company ==
){
echoError;
} else {
mail(nnorman@dimplexthermal.com,mobile app message,$ MessageText,$ Headers);
echoSuccess;
}
?>


解决方案

我最后使用以下代码和post方法我的php。你只需要确保你的div命名约定符合你的代码。这张贴的表单的结果和交换div与谢谢你的消息。请参阅下面的HTML和Javascript。

 < div data-role =content> 
< form id =myform>
< div data-role =fieldcontain>
< label for =name>名称:< / label>
< input type =textname =nameid =namevalue =/>
< / div>
< div data-role =fieldcontain>
< label for =email>电子邮件:< / label>
< input type =emailname =emailid =emailvalue =/>
< / div>
< div data-role =fieldcontain>
< label for =company>公司名称:< / label>
< input type =textname =companyid =companyvalue =/>
< / div>
< input type =submitname =submitvalue =Submitdata-icon =stardata-theme =b/>
< / form>

< / div>
< div data-role =contentstyle =display:noneid =formResponse>
谢谢,您的报价已经收到,您很快就会收到我们的回复。
< / div>

Javascript

  $(document).ready(function(){
//当提交id =myform的表单时...
$ #myform)。submit(function(){
//将序列化数据发送到mailer.php。
$ .post(mailer.php,$(#myform)。serialize ),
//接受我们的repsonse,并替换formResponse
// div中的任何值

function(data){
$ #myform)。html($(#formResponse)。html());
}
);
return false;
});

});


I am trying to process my form through a live server from my native app without leaving the page. Below is the code I am using for the form, the JQuery and the PHP, but when i send it, the page goes blank and puts the string in the URL bar. Can I get some help with my code please. I shortened the form on this to make it easier to read, i have alot of other fields as well. Do I need to have them all listed in the javascript?

HTML on Form

<form action="http://mobile.koolantkoolers.com/mailer.php" method="get">
  <div data-role="fieldcontain">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" value=""  />
</div>
<div data-role="fieldcontain">
  <label for="email">Email:</label>
  <input type="email" name="email" id="email" value=""  />
</div>

  <div data-role="fieldcontain">
    <label for="company">Company:</label>
    <textarea cols="40" rows="8" name="company" id="company"></textarea>
  </div>
<input type="button" onclick="submit()" value="submit" data-icon="star" data-theme="b" />              
  </div>
  </form>

JavaScript:

$.post('http://mobile.koolantkoolers.com/mailer.php', {

// These are the names of the form values

Name: $('name').val(),
Email: $('email').val(),
Company: $('company').val()

// HTML function

}, function (html) {
    // Place the HTML in a astring
    var response=html;

    // PHP was done and email sent
    if (response=="success") {
        alert("Message sent!"); 
    } else {

        // Error postback
        alert("Sorry please fill all fields!"); 
    return false;
   }
});

and then PHP

<?php

// VARS
$Name=$_GET["name"];
$Email=$_GET["email"];
$Company=$_GET["company"];
$Headers = "From:" . $Email;

//VALIDATION
if(
$Name=="" ||
$Email=="" ||
$Company==""
) {
    echo "Error";
} else {
    mail("nnorman@dimplexthermal.com","mobile app message",$MessageText, $Headers);
    echo "Success";
}
?>
解决方案

I ended up using the following code and post method on my php. You just need to make sure your div naming convention matches up to you code. This posts the results of the form and swaps the div out with a thank you message. See my HTML and Javascript below.

<div data-role="content">
<form id="myform">
  <div data-role="fieldcontain">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" value=""  />
</div>
<div data-role="fieldcontain">
  <label for="email">Email:</label>
  <input type="email" name="email" id="email" value=""  />
</div>
<div data-role="fieldcontain">
  <label for="company">Company Name:</label>
  <input type="text" name="company" id="company" value=""  />
</div>        
<input type="submit" name="submit" value="Submit" data-icon="star" data-theme="b" />
</form>

</div>
<div data-role="content" style="display:none" id="formResponse">
    thank you, your quote has been received and you will hear back from us shortly.
    </div>

Javascript:

$(document).ready(function() {
            //When the form with id="myform" is submitted...
            $("#myform").submit(function() {
                //Send the serialized data to mailer.php.
                $.post("mailer.php", $("#myform").serialize(),
                    //Take our repsonse, and replace whatever is in the "formResponse"
                    //div with it.

                    function(data) {
                    $("#myform").html( $("#formResponse").html() );
                    }
                );
                return false;
            });

        });

这篇关于Phonegap原生应用程序,通过PHP邮件程序在活动服务器上提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 04:26