PHP code example of flsouto / htbutton

1. Go to this page and download the library: Download flsouto/htbutton library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flsouto / htbutton example snippets



lSouto\HtButton;

$button = new HtButton("action");

echo $button;


use FlSouto\HtButton;

$button = new HtButton("action", "Save");

echo $button;

use FlSouto\HtButton;

$button = new HtButton("action");
$button->label("Save");

echo $button;


$button = new HtButton("action");
$button->inline(true);

echo $button;


$button = new HtButton("action");
$button->inline(true);
$button->inline(false);

echo $button;


$button = new HtButton("action", "Delete");
$button->attrs(['style'=>['background'=>'red','color'=>'yellow']]);

echo $button;


$button = new HtButton("action", "Delete");
$button->attrs(['id'=>'delete']);

echo $button;


$_REQUEST['delete'] = 1; // pretend a form has been submitted

$button = new HtButton('delete');
$button->context($_REQUEST);

if($button->value()){
	echo 'Deleting...';
}



$_REQUEST['action_delete'] = 1; // pretend a form has been submitted

$updateBtn = (new HtButton('action_update'))->context($_REQUEST);
$deleteBtn = (new HtButton('action_delete'))->context($_REQUEST);

if($updateBtn->value()){
	echo 'Updating...';
}

if($deleteBtn->value()) {
	echo 'Deleting...';
}



$_REQUEST['action'] = 'update';

$updateBtn = new HtButton('action','Update');
$updateBtn->attrs(['id'=>'update'])->context($_REQUEST);

$deleteBtn = new HtButton('action','Delete');
$deleteBtn->attrs(['id'=>'delete'])->context($_REQUEST);

if(isset($_REQUEST['action'])){
	switch($_REQUEST['action']){
		case $updateBtn->id() :
			echo 'Updating...';
			break;
		case $deleteBtn->id() :
			echo 'Deleting...';
			break;
	}
}