Input controls for Sitemagic CMS
The GUI library contains the
SMInput class which represents all HTML input controls (Text, Password, Hidden (text), File, Radio, Checkbox, Button, Submit (button), Reset (button), Textarea). Some (not all) of the controls are previwed in the table below.
Complete list of input controls
- Text (single line)
- Textarea (multi line)
- Password
- File upload
- Radio button
- Checkbox
- Hidden field
- Button
- Submit button
- Reset button
Working with input controls in code
All input control types are defined using the SMInput class as shown below. Which type of input control is created, depends on the
SMInputType argument passed to the SMInput class constructor.
$text = new SMInput("UniqueId1", SMInputType::$Text);
$pass = new SMInput("UniqueId2", SMInputType::$Password);
$upload = new SMInput("UniqueId3", SMInputType::$File);
$checkbox = new SMInput("UniqueId4", SMInputType::$Checkbox);
$radio = new SMInput("UniqueId5", SMInputType::$Radio);
$button = new SMInput("UniqueId6", SMInputType::$Submit);
Controlling the behaviour and appearance of input controls can be done using a set of functions on each input control object:
// Set control width
$text->SetAttribute(SMInputAttribute::$Style, "width: 150px");
// Register JavaScript event listener
$text->SetAttribute(SMInputAttribute::$OnKeyPress, "return suppressEnter(event)");
// Assign initial value
if ($text->GetValue() === null)
$text->SetValue("Enter name here..");
// Get value from input
$value = $text->GetValue();
// Setting and getting checked state for checkbox and radio buttons
$checkbox->SetChecked(true);
$checked = $checkbox->GetChecked();
// Determine whether an input control triggered a post back (page submitted)
$clicked = $button->PerformedPostBack();
To turn the input control object into HTML, simply invoke the Render function:
$output = "";
$output .= "<br>" . $text->Render();
$output .= "<br>" . $pass->Render();
$output .= "<br>" . $upload->Render();
$output .= "<br>" . $checkbox->Render();
$output .= "<br>" . $radio->Render();
$output .= "<br>" . $button->Render();
Radio buttons are a bit different from other input controls. If multiple radio buttons are related (grouped), allowing only one of them to be selected, these radio buttons must be constructed with the same unique ID, but have different values set.
// Create radio buttons
$radioRed = new SMInput("ColorPicker", SMInputType::$Radio);
$radioRed->SetValue("Red");
$radioGreen = new SMInput("ColorPicker", SMInputType::$Radio);
$radioGreen->SetValue("Green");
$radioBlue = new SMInput("ColorPicker", SMInputType::$Radio);
$radioBlue->SetValue("Blue");
// Check whether a specific radio button was selected
if ($radioRed->GetChecked() === true)
// Do something here..
else if ($radioGreen->GetChecked() === true)
// Do something different here..
else if ($radioBlue->GetChecked() === true)
// Do something different here..