July 1, 201115 yr Please excuse the silly question! I've been learning javascript. I know how to make a form, well good enough to get a decent mark for my code at college anyway. But back in the real world, I've realised I have no idea where the code goes! In the assignment we did at college I believe the data was going off to my tutor's server. However we just learnt how to build a form, and not how to retrieve the data. I know the code is sent in the header or appended to the URL - but then what? (I can't ask my tutors, we're on holiday). Or to put it another way, if you looked at some code that someone else had built could you tell where it was going to? And does the data usually go into a database, or would / could you set it up to be emailed to an email account perhaps? Sorry for the dumb ass question, I'd be really grateful if someone could enlighten me, thanks! Edited July 1, 201115 yr by Becca B
July 1, 201115 yr I'll give some demo code to help explain: <form action="http://somewebsite.com/form-process.php" method="post"> <input type="text" name="name" value="" /> <input type="text" name="email" value="" /> <input type="submit" value="Send" /> </form> For that code above, everything is being posted to a script at somewebsite.com/form-process.php. PHP is generally the language used to process forms (there are many, many alternatives). Posted data does not go into the address bar, but if we were to change the method to "get", the request sent would be: http://somewebsite.com/form-process.php?name=whatever&email=whatever To look at the PHP side of things... To start with, we'll use method="post" in the form to POST data (you would set the action="THIS BIT" to point to this following script): <?php if (!empty($_POST)){ echo 'The $_POST array:<br />'; print_r($_POST); echo "<br /><br />And to loop through them all:<br /><ul>"; foreach($_POST as $key => $val){ echo "<li>$key: $val</li>"; } echo "</ul>"; } ?> If we were using method="get" we would simply switch $_POST to $_GET. You can also use $_REQUEST which can be used to get both posted and 'get' data, but which also includes the PHPSESSID variable which is a unique session cookie. You can of course email the information sent - you can literally do whatever you want with it. Edited July 1, 201115 yr by andyl
Create an account or sign in to comment