Phonegap联系表单不能通过PHP工作 [英] Phonegap contact form not working over PHP

查看:144
本文介绍了Phonegap联系表单不能通过PHP工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题

I´m having a very odd problem

我在HTML5中使用phonegap构建移动应用程序,将其编译为本机应用程序。

I´m building a mobile app in HTML5 using phonegap to compile it to a native app.

在这个应用程序内是一个联系表单,我不能让它工作。我尝试了一切我可以想到的。但每次我提交表单,我收到的PHP的部分的代码在我的屏幕上。
显然,该应用程序在浏览器上工作正常,但不是在我的iphone。

Inside that app is a contact form and I can´t get it to work. I tried everything i could think of. But every-time i submit the form i receive the code of the php part on my screen. Obviously the app works just fine on the browser, but not on my iphone.

我甚至尝试使用iframe,并在其中添加了相同的结果。

I even tried using an iframe and added the form there, with the same results.

是。如何在我的应用程序中添加联系人表单(需要向客户端电子邮件发送用户信息)

So my question is. How do i add a contact form (needs to send user info to the client email) inside my app

任何帮助将受到高度赞赏

Any help will be highly appreciated

感谢

推荐答案

您的结构应该是这样的如果做整体的方法(html5到native通过Titanium / Phonegap)

Your structure should be like this if doing holistic approach (html5 to native via Titanium/Phonegap)

/projects/apps/html5app/index.html
/projects/apps/html5app/contact.html

/projects/apps/html5app/assets/js/phonegap.js
/projects/apps/html5app/assets/js/jquery.js

/projects/apps/html5app/assets/css/css.css

/projects/apps/html5app/assets/images/logo.jpg
/projects/apps/html5app/assets/images/button.jpg

在contact.html中,您需要使用PHP文件指向活动服务器

in contact.html you need to point to a live server with the PHP file

<form action="https://service.cdn-app.com/contact-form.php" method="get">

然后使用回发以AJAX或JSON提交感谢页面,

And then use a postback to submit a thanks page in AJAX or JSON so the user is not prompted to leave the app.

更新 - 更简单的方法就是这样按钮

Alternatively UPDATE - Easier approach is just do button like this

<input type="button" onclick="submit()" value="submit contact"/>

然后在你的jQuery上,你可以做他们的行动(他们不会离开你的应用程序,触发替换div与感谢等)

Then on your jQuery you can do the action their (they won't leave your app and you can trigger a replace div with thanks etc)

//启动jQuery形式的流程引擎

// Start the jQuery form process engine

$.post('https://service.cdn-app.com/contact-form.php', {

    // These are the names of the form values

    FirstName: $('#FirstName_input').val(),
    LastName: $('#LastName_input').val(),
    Email: $('#Email_input').val(),
    MessageText: $('#MessageText_input').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;
    }
});



PHP SAMPLE



PHP SAMPLE

<?php

    // VARS
    $FirstName=$_GET["FirstName"];
    $LastName=$_GET["LastName"];
    $Email=$_GET["Email"];
    $MessageText=$_GET["MessageText"];
    $Headers = "From:" . $Email;

    //VALIDATION
    if(
    $FirstName=="" ||
    $LastName=="" ||
    $Email=="" ||
    $MessageText==""
    ) {
        echo "Error";
    } else {
        mail("youradmin@cdn.com","mobile app message",$MessageText, $Headers);
        echo "Success";
    }
?>

这篇关于Phonegap联系表单不能通过PHP工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆