Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML Recording data in forms

I am very new to coding and decided to learn html and i am trying to make a form but i havent really found a good explanation on how to record the data entered into the form. right now my code looks like this.
[CODE title="Form"]<form>
<textarea required minlength="10" maxlength="100" rows="5" cols="30" name="contact" id="contact">what would you like to say</textarea>
<br>
<input type="submit" value="submit">
</form>[/CODE]
What can I do to have it record the data somewhere?
 
So, a HTML form by itself doesn't have any ability to save data. For that you'll need a server side language, such as PHP as well as possibly a database like MySQL.

Here's a simple example of how to capture the form values and display them back to the user:

However, that only captures them for that page load, reload and they're gone forever. To keep them, you'll either need to use PHP to write them to a file on your server (which isn't the most secure) or you will need to incorporate a MySQL database, so that each time the form is filled out the values are saved as a record in the database.

So, to save the record in a database the flow would be:

- User fills out form
- Form submits to a PHP file
- PHP file validates the form (ensures all fields are correct / filled out)
- PHP saves the data to a MySQL database
- User sees a confirmation screen that their data was submitted
 
So, a HTML form by itself doesn't have any ability to save data. For that you'll need a server side language, such as PHP as well as possibly a database like MySQL.

Here's a simple example of how to capture the form values and display them back to the user:

However, that only captures them for that page load, reload and they're gone forever. To keep them, you'll either need to use PHP to write them to a file on your server (which isn't the most secure) or you will need to incorporate a MySQL database, so that each time the form is filled out the values are saved as a record in the database.

So, to save the record in a database the flow would be:

- User fills out form
- Form submits to a PHP file
- PHP file validates the form (ensures all fields are correct / filled out)
- PHP saves the data to a MySQL database
- User sees a confirmation screen that their data was submitted
thank you this is so helpful
 
What does your local development environment look like? You will need a local web server running PHP in order to work with PHP, you can't just load it in a browser like with HTML.

I recommend WAMPServer if you're on Windows: https://sourceforge.net/projects/wampserver/
For Mac a good one is Laravel Valet: https://laravel.com/docs/8.x/valet

Once you have a local dev server that supports PHP you should be able to run a PHP file by going to the server's URL and loading the file.

Are you on Windows or Mac?
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom