Form Definition (callable)

array key: form_definition
returns array of array

The form_definition callable returns array $input_form for displaying the input form. In general, the $input_form array has some values which are used to define the form inputs and then other values become HTML input form tag attributes. Empty array values that are key only become singleton attributes. Specifically the key of the array becomes the name of the input, textarea or dropdown. Use type to define HTML5 inputs for validation.

The label fields define the input labels. If required is set required will be noted in the input label.

Furthermore type is either an HTML5 input type, or a textarea or select.

For a select option the usekey boolean defines whether the select options will have value attributes or not, the options array is an array to populate select options and values.

Radio and file inputs not currently supported.

HTML5 types will validate data well and setting the required attribute with a blank value will make the HTML5 input required.

function saturn_tables_cars_input_form_definition() {
	
	global $wpdb;
	
	if (count($wpdb->get_var("SHOW TABLES LIKE 'saturn_tables_cars'"))) {
		$countries = $wpdb->get_col( "SELECT DISTINCT country FROM saturn_tables_cars ORDER BY country" );
	} else {
		$countries = array();
	}
	
	$input_form['make'] = array('label'=> "Make", "required" => "", 'type'=>"text" );
	$input_form['model'] = array( 'label'=> "Model", "required" => "", 'type'=>"textarea", 'rows'=>"5", 'cols'=>"30", 'style'=>"max-width: 500px;");
	$input_form['mpg'] = array ('label'=> "MPG", "required" => "", 'type' => "number", 'step'=>".1");
	$input_form['cylinders'] = array ('label'=> "Cylinders", "required" => "", 'type' => "number", 'step'=>"1");
	$input_form['weight'] = array ('label'=> "Weight", "required" => "", 'type' => "number", 'step'=>"1");
	$input_form['model_year'] = array ('label'=> "Model Year", "required" => "", 'type' => "number", 'step'=>"1");
	$input_form['country'] = array ('label'=> "Country", "required" => "", 'type' => "select", 'options' => $countries , 'usekey' => false);
	
	return $input_form;
	
}