More classes

Class gpost

Make easy post requests from the server with the constructor of the class. Use:

$postData = ['id'=> 100];
$args = ['type'=> 'x-www-form-urlencoded'];

$response = new gpost('', $postData, $args);
$list = $response->json();


  • $url:string the url, or
  • $data:assoc array (optional) posted data
  • $args:assoc array (optional) options
  • $name:string (optional) base name

Option keys

  • type: x-www-form-urlencoded|json Default: json
  • ignore_errors:boolean Default: true
  • header:assoc array of headers
  • method:string Default: POST
  • url:string the url, applies only on method set() (see below)

body ()

Returns the row contents of the response

json ()

Returns the response data in object format or null

set ($name, $args)

(static) Sets the prefix arguments of a base gpost


  • $name:string the base name
  • $args:assoc options to save


$postData = ['id'=> 100];
$args = ['type'=> 'x-www-form-urlencoded'];

// directly to endpoint
$response = new gpost('', $postData, $args);

// using a base, you can skip sending empty arguments as third parameter,
// and send the base api name
$args['url] = '';
$args['header'] = ['Authorization'=> 'Bearer <token>'];
gpost::set('api_ex', $args);
$response = new gpost('get', $postData, 'api_ex');

Class gForm

Displays forms

posted ()

(static) It compares the value formToken from the request (GET/POST) with the stored token in session. If the name is specified the stored token will be removed in this function. Return boolean.


  • $name: (optional) the form token name.

verifyToken ($name, $check)

Compares a value to the stored token in session. Returns boolean


  • $name: the form token name
  • $check: the value

getToken ()

(static) Creates and returns a new form token.


  • $name: the form token name

hiddenInput ($name)

(static) Prints a hidden input with the value of the form token.


  • $name: (optional) the form token name

html ()

(static) Prints the input fields for a form.


  • $fields:assoc the fields to print as input elements
  • $values:assoc (optional) values
  • $preffic:string (optional) preffix fot the input names
  • $suffix:string (optional) suffix fot the input names


    'options'=>[0=>'Group A', 0=>'Group B']

input ($name, $op[,$ov, $key])

(static) Prints an input tag.


  • $name:string the input name
  • $op:assoc the field schema
  • $ov:string (optional) current value
  • $key:string (optional) input label

addInputType ($name, $function)

(static) Create a new input type for gForm class.


  • $name:string the input type name
  • $function:function a function that returns the html

Function Parameters

  • $name:string the input name
  • $field:assoc the field schema
  • $value:mixed the current value


gForm::addInputType('group-select', function($name, $field, $value) {
  // a web coomponent that will be rendered with vuejs
  $valueProp = 'value="' . $value . '"';
  $dataProp = 'data-group="' . json_encode($field['options']) . '"';
  return "<group-select $valueProp $dataProp></group-select>";