Reputation: 65
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
Upvotes: 2
Views: 3156
Reputation: 27087
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
$.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
// 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";
}
?>
Upvotes: 3