form_submit()

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

Description

Generates an HTML submit button element with type="submit" for sending form data to the server.

Parameters

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

Return Value

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

Example #1: Basic Submit Button

PHP
echo form_submit('submit-btn');

// Output:
// <button type="submit" name="submit-btn">Submit</button>

Example #2: Submit Button with Custom Text

PHP
echo form_submit('action', 'Save Changes');

// Output:
// <button type="submit" name="action">Save Changes</button>

Example #3: Multiple Action Buttons

PHP
echo form_submit('action', 'Save Draft');
echo form_submit('action', 'Publish Now');
echo form_submit('action', 'Delete');

// In controller: $action = post('action', true);
// Returns: 'Save Draft', 'Publish Now', or 'Delete'

Example #4: Disabled Submit Button

PHP
$attributes = [
    'disabled' => 'disabled',
    'class' => 'warning'
];
echo form_submit('submit', 'Processing...', $attributes);

// Output:
// <button type="submit" name="submit" disabled="disabled" class="warning">Processing...</button>

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 submit buttons. This code assumes Trongate CSS is loaded on your webpage:

View File
<?php
echo form_submit('btn1', 'Default Submit');
echo form_submit('btn2', 'Success Action', ['class' => 'success']);
echo form_submit('btn3', 'Danger Action', ['class' => 'danger']);
echo form_submit('btn4', 'Warning Action', ['class' => 'warning']);
echo form_submit('btn5', 'Inverse Action', ['class' => 'inverse']);
echo form_submit('btn6', 'Alt Style', ['class' => 'alt']);
?>

Submit vs Button: This creates <button type="submit"> elements that automatically submit forms. For non-submitting buttons, use form_button() instead.

  • Submit buttons automatically submit their parent form when clicked
  • Submit buttons are included in POST data - use post('button_name', true) to check which was clicked
  • Use different $value parameters to distinguish multiple submit buttons
  • Add disabled attribute during processing to prevent double-submission
  • Available CSS classes: success, danger, warning, inverse, alt

Common Use Cases

  • Form submission for data processing
  • Multiple action forms (Save, Publish, Delete)
  • Wizard-style forms with Next/Previous buttons
  • Search forms with specialized submit buttons
  • Forms requiring confirmation before submission