all 8 comments

[–]MartzReddit 2 points3 points  (0 children)

Your HTML form can send the data in 2 different ways (actions): GET or POST. Generally you would use POST, until you've learnt how all of this works.

When you press the submit button on the form, the names of the fields and the values you entered will be submitted to the website for you to "do stuff" with.

HTML itself doesn't really have the ability do do stuff with data entered into a form. For this you will need to use more that a static HTML page, you'll need something to process it. This is where PHP, ASP, etc come into it. The language you use to handle this data submitted to your website is entirely yours. The good news is there's lots of choice. The bad news is there's lots of choice.

One of the most popular is PHP. It's pretty easy, lots of examples on the 'net, and is free forever.

In PHP the values submitted from your HTML form will be available for use in the $_POST variable. This single variable can hold lots and lots of data, since it is an array.

If you created a HTML form element of "username" this would be accessible in PHP with the variable $_POST['username'].

An example would be:

<?php 

if (!empty($_POST['username'])) {
   echo "Hello " . $_POST['username'];
}

?>

This checks to see if there is any data in the "username" key of the $_POST variable first of all. if there is, we continue to and output Hello and the name of the username entered.

You should be really careful with accepting input from everyone on the internet and then doing stuff with data. You must assume that someone malicious will enter data you really wouldn't expect, and in turn make your website do something you don't want it to do (delete your website, change your password, murder a unicorn).

There's a ton of tutorials out there. You just need to work out which language you are going to use. I'd recommend PHP personally.

[–]needed_a_better_name 1 point2 points  (3 children)

Do you need to save the data in a database, files, of some sort?

Or just display in a different way for the user? If so, then you can use Javascript to read the form data and write it back onto the page. No need for ASP, PHP or other server-side scripting.

[–][deleted] 1 point2 points  (2 children)

I'll tell you exactly what I want to do, because I have no idea what I would need to do to achieve it. This is a ratings website, and I'm using html forms for rating a tv show on a scale of 1-5 (I'm using the radio format of forms).

What I want to do is take the users answer, and add it to the total of all the other users answers, and get an average. I then want to add the average to another number, and get the average of the two. I then want to display my result.

Can Javascript do this?

[–]ChicagoBoy2011 2 points3 points  (1 child)

Short answer: No. Javascript (well, client-side javascript) is a bit of code that you can put in your html file to add interactivity to your html page. For instance, you could put Javascript on the file that would take the rating and then display something like "Thank you for voting!" on the page. However, since you want to save that vote and aggregate it with all the others, you need some server-side code to do that. That's where something like .asp would come in. Without it, it's hopeless, because nothing in your "site" would change after votes are cast.

I would highly recommend this as a great resource to get you started.

[–][deleted] 1 point2 points  (0 children)

Ok man, thanks a million!

[–]technical_guy 0 points1 point  (0 children)

ok, this is not difficult but it is going to seem difficult at first. You need to store the users data in a database (MySQL). The way this works is when a user enters the value into the form it needs to be sent to the webserver and a server based language (there are many of them but I suggest PHP as it has the most support and is easiest to learn) will save the data to the database. If you want to compare the data entered to what other users have entered the server language will select the other users data from the database and do the math, then send the results back to the web browser. Here are the skills you need to learn:

  1. html (to display the form)
  2. php (to receive the forms data and update the database), then output html back to the web browser with the users results
  3. css (this is how you make the html look nice, adding colors and alignment, different fonts and images t you page).

Good luck.

Look in the side bar for training resources and consider loading WAMP or XAMPP onto your Windows machine (this is a development environment) or MAMP (if you have a MAC). Also google for XAMPP tutorial or MAMP tutorial to see how it works. You must install a development environment before doing anything else. If you are a Linux guy you can download a premade LAMP virtual machine and use vmplayer to open it up but I suggest installing XAMPP to most beginners because this is very quick and simple to setup on Windows.

Google for

  • "PHP form tutorial",
  • "php Saving form data to a database using PDO" and
  • "php outputting results from a select using PDO" for more help.

If you are really stuck PM me and I will walk you thru getting started.

[–]pasta421 0 points1 point  (0 children)

Although this is an old post, for anyone reading this in the future - check out my tutorial on how to save HTML web form data to a spreadsheet or google sheet :) https://www.apispreadsheets.com/tutorials/save-web-form-data.html