dongze8698 2013-03-04 01:10
浏览 56

使用PhoneGap发送PHP表单

Last thread was riddled with errors, made a mistake when pasting it.

To start off, I've been playing around with PhoneGap, and what I'm trying to do eventually is build an app with a contact form that will email the results to an email of my choice (along with a picture taken in the camera app) (or post results to a server even)

I found this and I've been trying to replicate it to get a starting feel of how my form would work, however, I can't seem to get it running.

Heres a step by step of what I have so far.

Index.html -> Just links to callsheet.html

callsheet.html

    <!DOCTYPE html>
<html>
  <head>
    <title>Send in CallSheet</title>

    <script type="text/javascript" charset="utf-8" src="js/cordova-2.5.0.js"></script>
    <script type = "text/javascript" charset="utf-8" src="js/index.js"></script>
    <script type="text/javascript" charset="utf-8">


    // Wait for Cordova to connect with the device
    //
    document.addEventListener("deviceready",onDeviceReady,false);
</script>

  </head>
  <body>
<form action="http://contest.phoenixamd.com/ANDROIDTEST/callsheet.php" method="post">
          <div class="form-element">

        <label for="msg">Message</label>
        <textarea id="msg" name="msg" placeholder="required" rows="5" required ></textarea>
      </div>
      <input type="button" value="submit contact"/>
      </form>
  </body>
</html>

callsheet.php (on my remote server)

    <?php
    require_once("class.phpmailer.php");


    $MessageText=$_POST["msg"];


    $mailer = new PHPMailer();
    $mailer->isSMTP();
    $mailer->CharSet='utf-8';
    $mailer->AddAddress("gabesteinberg@me.com", "Gabe");
    $mailer->Subject="Mobile App Message";
    $mailer->From = 'test@phoenixamd.com';
    $mailer->Body = $MessageText;


    //VALIDATION
    if(
    empty($MessageText)
    ) {
        echo "Error";
    } else {
        $mailer->Send();
        echo "Success";
    }

?>

index.js (where im keeping my jquery)

    // When the document has loaded...
$(document).ready(function() {
  // Bind this action as a function to be executed when the button is clicked...
  $('input[type="button"][value="submit"]').click(function() {
    $.post('http://contest.phoenixamd.com/ANDROIDTEST/callsheet.php', {


      MessageText: $('#msg').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("Please fill all fields!"); 
            return false;
          }
    });
  });
});

I've tried following steps taken here and here but cant seem to figure out whats wrong... When I hit submit, absolutely nothing happens.

My PHP file works, and if I submit via this it echoes success and sends the email.

If I change my php to submit instead of button, it works, but thats just using the html and php, not the actual JS of the app itself.

  • 写回答

2条回答 默认 最新

  • doujiao2014 2013-03-04 01:22
    关注

    First of all, i don't think the request will be allowed if your domain is not whitelisted in config.xml.

    I cannot tell from your text on which device your example fails - if i was on android i'd just grep the logcat output for any errors, which the CordovaWebView will send there by default.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线