To organize data in such forms, you can use arrays of HTML forms. Suppose we present a huge amount of data about a house. I would divide the data into sections, for example: general
, geo
, features
, descriptions
and compose a form like this.
<form> <fieldset> <legend>General information</legend> <input type="number" name="general[pax]" value="" placeholder="Pax" /> <input type="number" name="general[pets]" value="" placeholder="Pets" /> <input type="text" name="general[type]" value="" placeholder="Type" /> </fieldset> <fieldset> <legend>GEO data</legend> <input type="text" name="geo[longitude]" value="" placeholder="Longitude" /> <input type="text" name="geo[latitude]" value="" placeholder="Latitude" /> </fieldset> <fieldset> <legend>Features</legend> <input type="checkbox" name="features[internet]" value="1" title="Internet" /> <input type="checkbox" name="features[pool]" value="1" title="Pool" /> <input type="checkbox" name="features[conditioner]" value="1" title="A/C" /> </fieldset> </form>
UPDATE: using the <fieldset>
and <legend>
tags and a bit of jQuery
(not shown) you can easily show / hide different groups and name them to your liking.
After submitting this form, you can access the following values:
$pets = (int)$_POST['general']['pets']; $features = $_POST['features']; $lon = (float)$_POST['geo']['longitude']; $lat = (float)$_POST['geo']['latitude'];
This will facilitate your development and reduce the effort to control / analyze / enumerate different groups of data.
UPDATE: or another possible option
<input type="text" name="params[param1]" value="" /> <input type="text" name="params[param2]" value="" /> <input type="text" name="params[param3]" value="" />
meanwhile in PHP
$params = $_POST['params'];
source share