Get the values entered by users

Access the input values in a form component

You can access the input values of a form component

You can access the input values that the user has input into the form component at any time, by calling the getInputValue function on the FormComponent object.

Get a single input value

You can get a single value that the user has currently entered into the form by using the getInputValue function. Note that getInputValue only returns a value if the user input something.

$selected_product = $form->getInputValue ('product_name');
$selected_status = $form->getInputValue ('delivery_date');

Text Field

Calling getInputValue with a text field returns a string which is the user's input.

$form->getInputValue ("product_name");

// Returns:
// "Potato Chips"

Calling getInputValue returns an object with 2 items:

  • text - which is the text of the selected item
  • index - which is the index of the seleted item (starting from 0)
$form->getInputValue("delivery_status");

// Returns:
// array(
//   'text' => "Refunded",
//   'index' => 1
// )

Multi Select field

Calling getInputValue returns an array with 2 items:

  • text - which is an array containing texts of selected items
  • index - which is the an array containing indices of the seleted items (starting from 0)
$form->getInputValue("item_category");

// Returns:
// array(
//   'text' => ["Condiments", "Snacks"]
//   'index' => [1, 2]
// )

Date Field

Calling getInputValue returns a string with date formatted in "YYYY-MM-DD" format.

$form->getInputValue ("sale_date");

// Returns:
// "2013-08-18"

Date Range Field

Calling getInputValue returns an array with two strings. The first string is starting date, and second string is the ending date.

$form->getInputValue ("sale_period");

// Returns:
// ["2013-07-18", "2013-08-18"]

Numeric Range Field

Calling getInputValue returns an array with two numbers. The first string is starting value, and second string is the ending value.

$form->getInputValue ("sale_amount");

// Returns:
// [42, 55]

Example for using this API

<?php

class SampleDashboard extends StandaloneDashboard { public function buildDashboard(){ $c1 = new FormComponent("c1"); $c1->setCaption("Test Form Component"); $c1->setDimensions (6, 6); $c1->addTextField('name', 'Name'); $c1->addSelectField('products', 'Products', array('Beverages', 'Chips', 'Cookies', 'Cakes', 'Dairy Products', 'Poultry'), array()); $c1->addMultiSelectField('cities', 'Cities', array('Bangalore', 'San Fransisco', 'New York', 'Melbourne', 'London', 'Rio De Jeneiro'), array()); $c1->addDateField('delivery_date', 'Delivery Date', array()); $c1->addDateRangeField('grace_period', 'Grace Period', array()); $c1->addNumericRangeField('units', 'Units in Stock', array(0, 100));

$kpi = new KPIComponent('kpi1');
$kpi->setCaption('Stock');
$kpi->setDimensions(4, 4);
$kpi->setValue(24);

$this->addComponent($kpi);
$this->addComponent ($c1);

$c1->onApplyClick(array($kpi), 'handleApply', $this);

}

public function handleApply($source, $target, $params) { $c1 = $this->getComponentByID('c1'); $kpi = $this->getComponentByID('kpi1'); $caption = $c1->getInputValue('products')['text']; $units = $c1->getInputValue('units');

$kpi->setCaption($caption);
$kpi->setValue($units[1]);

} }

$db = new SampleDashboard(); $db->renderStandalone();