form_button()

function form_button(string $name, ?string $value = null, array $attributes = []): string

Description

Generates an HTML button element with type="button". These buttons require JavaScript for interactivity and do not submit forms.

Parameters

Parameter Type Description
$name string The name attribute for the button element.
$value string|null (optional) The button's visible text. Defaults to "Submit".
$attributes array (optional) HTML attributes for the button element. Defaults to an empty array ([]).

Return Value

Type Description
string An HTML button element with type="button".

Example #1: Basic Button

Example #2: JavaScript Action Button

Example #3: Reset Button for Forms

Example #4: Button with Data Attributes

Button Styling

Available CSS Classes

Your buttons may have different colors than those displayed above. The actual appearance depends on your Trongate CSS theme.

Try It Yourself

Test different CSS classes with your buttons. This code assumes Trongate CSS is loaded on your webpage:

Button vs Submit: This creates <button type="button"> elements. For form submission, use form_submit() instead.

  • Type="button" buttons require JavaScript for functionality
  • Can be used as reset buttons with type="reset" attribute
  • Use data attributes (data-*) to store custom information
  • Available CSS classes: success, danger, warning, inverse, alt
  • Buttons are not included in form submission data

Common Use Cases

  • Modal triggers and dialog openers
  • Form reset/clear functionality
  • JavaScript-powered actions (show/hide, filtering, sorting)
  • Cancel buttons that navigate away without submitting
  • Interactive elements that trigger AJAX requests