Phonegap contact form not working over PHP

拈花ヽ惹草 提交于 2019-12-29 07:21:09

问题


I´m having a very odd problem

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

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.

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

Thanks


回答1:


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

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">

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"/>

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)

// Start the jQuery form process engine

jQUERY Sample

$.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

    // 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";
    }
?>


来源:https://stackoverflow.com/questions/12597891/phonegap-contact-form-not-working-over-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!