当用户点击“提交”按钮时,将信息记录到日志文件中。

3
这个问题的解决方案很可能涉及到数据库,但不幸的是,Squarespace与许多数据库(如mySQL)并不兼容。我的问题是,是否有任何方法或代码可以在不设置数据库的情况下捕获一些信息(用户名、IP地址、位置、时间戳),当站点上的用户点击“提交”按钮时将其导入日志文件?我相信一定有办法,我很抱歉没有准备好与我的问题相关的任何代码,我仍在研究解决方案。我可以提供按钮的jQuery代码:
<body>
  <div id="popup" align="right">
    <object type="text/html" id="terms" data="/popup-form" width="60%" height="90%" style="overflow: auto">
    </object><br>
    <form>
      <input id="cancel" type="button" value="Cancel" onClick="history.go(-1);return true;"/>
      <input id="submit" type="submit" value="I Agree" />
    </form>
  </div>

  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
  <script>
    $("form").on("submit", function(e){
      e.preventDefault();
      $("#popup, #overlay").hide();
      $.cookie("popup", "displayed", { expires: 7 });
    });
    var hasSeenpopup = $.cookie('popup');
    if(!hasSeenpopup){
      $("<div>",{ id : "overlay" }).insertBefore("#popup");
      $("#popup").show();
    }
  </script>
</body>

如果你真的想编程,不要使用Squarespace - Squarespace是给那些不会编程的人用的。 - user557846
决定已经做出,所以我们需要在Squarespace环境中实现一些东西;没有其他选择。我正在阅读有关Parse Javascript SDK的更多信息:https://parse.com/docs/js/guide,请问有人知道它在Squarespace中的运行情况如何? - Khepfer Haru
1个回答

0
使用jQuery发送AJAX数据,请使用以下代码:
$("form").on("submit", function(e){
    //your previous code
    $.ajax({
         type: "POST",
         url: "myform.php",
         data: {'form': $("form").serialize()},
         success: function(message) {
            //do whatever
         }
      });
   return false;
});

之后在myform.php中处理$_POST,并将数据写入some.log

$string = '';

$date = date('Y-m-d H:i:s');

$ip = '';
if (!isset($_SERVER['SERVER_ADDR'];))
   $ip = $_SERVER['SERVER_ADDR'];

$string = $date.' : '.$ip.PHP_EOL;

file_put_contents('some.log', $string,  FILE_APPEND);

关于位置 - 这可能会存在问题,请对此做一些了解帖子

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接