Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle huge form [closed]

Tags:

forms

php

mysql

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

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

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

like image 903
d7p4x Avatar asked Jul 30 '12 11:07

d7p4x


2 Answers

To organise data in such forms, you can use HTML form arrays. Assume we submitting huge amount of data about some house. I'd split data into sections for example: general, geo, features, descriptions and compose 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 <fieldset> and <legend> tags and a bit of jQuery (not demonstrated) you can easily show/hide different groups and name them at your taste.

After submitting such form you will be able to access values like:

$pets = (int)$_POST['general']['pets'];
$features = $_POST['features'];

$lon = (float)$_POST['geo']['longitude'];
$lat = (float)$_POST['geo']['latitude'];

It will ease your development and reduce efforts to control/parse/enumerate different groups of data.

UPDATE: or one more possible variant is

<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
like image 143
Paul T. Rawkeen Avatar answered Nov 13 '22 16:11

Paul T. Rawkeen


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

like image 36
Rainer.R Avatar answered Nov 13 '22 16:11

Rainer.R