OM The Eternity OM The Eternity - 25 days ago 12
HTML Question

How can an id of input field can be read by PHP?

I have an HTML input field, and I have every input field specified with some id, now how can I use this input field id to identify the field.

Example:

<input type='text' id='float' name='attributename' value='' maxlength='30'/>


I need to verify the id of input field for float and then insert the input field's value in to db in particular field.

Please help me out..

Answer

It depends which method you use for transferring the data (specified by the method attribute of the form element).

E.g. with:

<form method="POST">
    <input type='text' id='float' name='attributename' value='' maxlength='30'/>
    <input type="submit" />
</form>

you can access the data in PHP via $_POST['attributename'] when the form is submitted. $_POST is an associative array that holds the data send via a POST request.

Note: The name of the input element is the important property, not the ID. The ID is not transferred to the server, it plays only a role in the DOM. Only the name and the value is send to the server. So if you probably want to set name="float".

Further information: Variables From External Sources. You also might want to read about $_POST and $_GET (GET is the other method. This is used to send data via the URL).

Comments