OM The Eternity OM The Eternity - 1 year ago 69
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.


<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 Source

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" />

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download