开发者

Recording form input on a server without php/asp

开发者 https://www.devze.com 2023-03-27 20:28 出处:网络
I have a small project to record some form input on a page that\'开发者_如何学运维s hosted on a bare bones Network Solutions account with no server-side scripting.I\'ve been trying to research solutio

I have a small project to record some form input on a page that'开发者_如何学运维s hosted on a bare bones Network Solutions account with no server-side scripting. I've been trying to research solutions and it seems the only way to do this is maybe by using a secondary account on a host that DOES have php and submit to it via ajax (I don't want the page to refresh so I'm assuming this would be necessary). I've never used ajax before and this project is due very soon so I'm looking for examples or solutions online that don't require a big learning curve. Can anyone suggest any resources?


If you don't want the page to refresh the only method is to make the form post into an 0x0 pixels iframe as ajax doesn't work cross-sites.

<html>
    <head></head>
    <body>
    <form action="http://www.example.org/otherHost.php" .... target="myIframe">
        .....
    </form>
    <iframe src="someblankdocument.html" name="myIframe" id="myIframe" width="0" height="0" frameborder="0"></iframe>
</html>


"recording" to a file is as easy as

file_put_contents( $file, $data );

if you install jquery making a post request to your php page is as easy as

$.post(
    "file.php",
    { data here }
    function(data) {
        alert("success");
    }
);

http://api.jquery.com/jQuery.post/

http://www.php.net/file_put_contents

If you want to put your data in a database it gets more complicated.


  1. You must use server-side processing to store form result from users.
  2. You don't need to use ajax to submit form to another account or location.

e.g. For example if you have two accounts foo.example.com and bar.example.com

In foo.example.com/index.html you can have a form that submit to bar.example.com:

<form action='bar.example.com/saveForm.php' method='post'>
   ...
</form>

And here is a very simple saveForm.php that save result to bar.example.org/data.csv, without validating the input:

<?php

$fp = fopen('data.csv', 'a');
fputcsv($fp, $_POST);
fclose($fp);

// Tell user then you got their data - normally should do error checking first
echo "Data saved. Thank you!";

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号