What is the difference between ID="" and NAME=""?

Asked

Viewed 1,368 times

0

I bought a Dashboard from the internet and when I came across the code I saw the following:

<input type="text" class="form-control round" id=" " placeholder="Your Username" required>

In the internet tutorials I saw that I need to take the command name="" so you can refer it to another file.

I wanted to know the difference between command NAME=" " for ID="" because apparently they serve the same function or I’m wrong?

It’s right I remove the id="" and put the name=""? I made this change and it worked with me (validation form in the database) however I was doubtful, the ID="" serves what?

  • name you associate a name for the input or form. When uploaded to PHP, you will use name to find its value. Already the id, it defines the identification in that code for the browser. It is used in Ajax or CSS.

1 answer

2

Well, as the name says ID is an "element" where this should be unique, that is, the name you put in the ID of an element, should not be repeated in the code, as it generates conflicts. Already the name works differently, the same you can use it from referencing a label of a form, until the part that you go through data for sending to the Database. The "Names" are the attributes where you reference in your backend to pick up the value of the inputs, which you fill in the information you want to store. More than that, the "Names" can be transformed into a kind of "Array" when placed []at the end of its decay; this serves for forms where you can have fields that are cloned and will have the same name, as Product, quantity, price etc.

  • so I’m just doing form validation, so I’m taking out the ID as it was and adding the name, there won’t be any problems right? only if later you want to work it with right ajax or css? how to use html and php no right problems?

  • Yes, the Form validation takes the data through the Name of the objects. Remembering that you can only capture the input value when the Form Ubmit is done, if you try to take DIV values and the like, I think only with AJAX and Jquery. With PHP, let’s assume that you have a registration form and need to capture the person’s name, using the $_POST['nome'] ( thinking that this is the name of your input ), the value of it is already captured. It is recommended to use the POST instead of GET for most submits, the POST sends more data and is more secure as it does not provide information through the page URL.

  • thank you very much if you could give you points! kk obg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.