Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

html - Phonegap contact form not working over PHP

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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("[email protected]","mobile app message",$MessageText, $Headers);
        echo "Success";
    }
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...