0

I have a form page and I would like to submit the form details to my server, and store the details within the server.

I need a script to send the client's request to the server and I thought of using JavaScript.

I came across XMLHttpRequest while searching.

Could anyone please point me in the right direction?

1 Answer 1

5

JavaScript is a client-side scripting language, it can not store anything on your server as you will need a server-side scripting language.

The first part of drawing a form and asking the user for the data is easy and can be done in HTML, and some jQuery if you would like it nice looking. The server-side will require a PHP/ASP script that will store or send the submitted data.

Example:

HTML (form.html):

<form method="POST" action="store.php">
Enter Your Name: <input type="text" name="fullname" />
</form>

PHP (store.php):

<?php
 foreach($_POST as $name=>$value)
 {
    $contents .= "$name = $value" . "\n";
 }

 // save locally in cache folder
 $fd = fopen("cache/filename.txt", "w");
 fwrite($fd, $contents);
 fclose($fd);

 // mail me the submitted data
 @mail("[email protected]", "some subject", $contents);

 // die in piece
 die();
?>
Sign up to request clarification or add additional context in comments.

4 Comments

I have this form page with a submit button ,the onclick parameter points towards a function which sends form details to the server, " onclick=172.16.151.31/receive.php " , the receive.php , would accept the parameters and store it in a text file .
Yes, your report.php should receive the passed form field information by parsing the $_POST server variable, then saving or sending it as illustrated above. The easiest way to check if the receive.pgp is getting the data is to enter a line like print_r($_POST);
the function which submits the form would be only having this entry right? function submitform() { document.myform.submit(); }
Depends, you can do the same single thing with Javascript in a 100 different ways.. but generally speaking, the code you showed is correct, assuming your form name is myform.. and you have the correct onclick inserted in place for the active button. Want my advise, check jQuery Ajax, much faster and much more accurate results ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.