Form Macros

Core Module


In order to avoid writing the same thing over and over, AsgardCms provides you with form macros that help to avoid writing the same code for form fields. This will generate the necessary code working for the AdminLTE backend theme.

They exists in two kinds, translatable fields and non translatable fields.

Translatable fields

Translatable Input

This is the method signature:

Form::macro('i18nInput', function ($name, $title, $errors, $lang, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $lang is the language of the input,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form::i18nInput('name', 'field title', $errors, $lang) !!} // Create view
{!! Form::i18nInput('name', 'field title', $errors, $lang, $object) !!} // Edit view

Translatable Textarea

This is the method signature:

Form::macro('i18nTextarea', function ($name, $title, $errors, $lang, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $lang is the language of the input,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form::i18nTextarea('body', 'field title', $errors, $lang) !!} // Create view
{!! Form::i18nTextarea('body', 'field title', $errors, $lang, $object) !!} // Edit view

Translatable Checkbox

This is the method signature:

Form::macro('i18nCheckbox', function ($name, $title, $errors, $lang, $object = null)
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $lang is the language of the input,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form::i18nCheckbox('is_online', 'field title', $errors, $lang) !!} // Create view
{!! Form::i18nCheckbox('is_online', 'field title', $errors, $lang, $object) !!} // Edit view

Translatable Select

This is the method signature:

Form::macro('i18nSelect', function ($name, $title, ViewErrorBag $errors, $lang, array $choice, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $lang is the language of the input,
  • $choice the possible choices,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form::i18nSelect(‘test’, ‘test’, $errors, $lang, [1,2,3]) !!} // Create view
{!! Form::i18nSelect(‘test’, ‘test’, $errors, $lang, [1,2,3], $object) !!} // Edit view

Non-translatable fields

These are pretty much identical to the translatable macros, except they don't have a $lang argument.

Normal Input

This is the method signature:

Form::macro('normalInput', function ($name, $title, $errors, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form::normalInput('name', 'field title', $errors) !!} // Create view
{!! Form::normalInput('name', 'field title', $errors, $object) !!} // Edit view

Normal Textarea

This is the method signature:

Form::macro('normalTextarea', function ($name, $title, $errors, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form:: normalTextarea('body', 'field title', $errors) !!} // Create view
{!! Form:: normalTextarea('body', 'field title', $errors, $object) !!} // Edit view

Normal Checkbox

This is the method signature:

Form::macro('normalCheckbox', function ($name, $title, $errors, $object = null)
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form:: normalCheckbox('is_online', 'field title', $errors) !!} // Create view
{!! Form:: normalCheckbox('is_online', 'field title', $errors, $object) !!} // Edit view

Normal Select

This is the method signature:

Form::macro('normalSelect', function ($name, $title, ViewErrorBag $errors, array $choice, $object = null, array $options = [])
  • $name is the name of the input (also called on the $object if given to fill the input),
  • $title is used for the place holder and label,
  • $errors is the errors message bag,
  • $choice the possible choices,
  • $object is the object used to fill the input,
  • $options an array of options that'll be sent to the Form::input method.

This will look like the following:

{!! Form:: normalSelect(‘test’, ‘test’, $errors, [1,2,3]) !!} // Create view
{!! Form:: normalSelect(‘test’, ‘test’, $errors, [1,2,3], $object) !!} // Edit view

Mobile Analytics