How to handle a huge form

I have a question, how do you handle huge data from forms with php and mysql?

I have the following: ~ 50 fields (text input, checkboxex, select, textarea)

After that, I need to save this in the MySQL database, and I need to select and filter this data. Do you have practice and what do you use in your projects?

+6
source share
2 answers

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']; // getting our isolated array of parameters $names = array_keys($params); // extracting names from array $values = array_values($params); // extracting values from array $mysql->insert($names, $values) // and trying to implement desired solution 
+6
source

I would divide the information into sections and only display / ask a subset in each section. Each section has a save / next button, and data is saved on each submit element.

+1
source

Source: https://habr.com/ru/post/921667/


All Articles