We saw before that the formatting option (example 6) allows you to format data before sending it to the browser. The inputFormat option can be thought of as the opposite – modifying user input data before it is inserted into the database.
$tg = new TableGear(array( "database" => array( "username" => "USERNAME", "password" => "PASSWORD", "database" => "DATABASE", "table" => "TABLE" ), "sortable" => "all", "editable" => "all", "loading" => array( "tag" => "img", "attrib" => array( "src" => "/images/icons/loading.gif", "alt" => "Loading", "class" => "loading" ) ), "formatting" => array( "price" => "currency[prefix=$,pad], "date" => "date" ), "totals" => array("price", "quantity"), "inputFormat" => array( "price" => "numeric", "date" => "timestamp" ) );
Basically, specifying an input format tells TableGear what type of data to expect. In the price column, we are expecting numeric data. Effectively, this means that TableGear will look for a number and ignore all other data. If the user input "$234,332.44 USD", the actual data inserted into the database would be "234332.44", and everything else would be ignored.
The timestamp format is more complex, but essentially the same idea. It will try to interpret user input in a way that makes sense as a date. Here, we are inserting it into the database as a raw timestamp, but if we wanted we could specify the date format to have more control over the format in the database.
When viewing the example, try entering "today" or "tomorrow" in the date column. You will find that the date related formats offer a lot of flexibility. For more information about input formats, see the documentation.