Skip to content

Defaults & Script Vars

Per-project key/value defaults and on-screen script variables.

10 functions. All require apis/main_webservices.php to be included.


On this page: hardDefaultGet ยท localWord ยท scr_Hide ยท scr_Show ยท scr_getvalue ยท scr_message ยท scr_setFocus ยท varSet ยท xDefault ยท xDefault2


hardDefaultGet()

Prototype

hardDefaultGet($xKey, $retifempty='')

Description

  • Reads a persistent project default (get-only form) with a fallback when absent.
  • Use when you only need to read a stored configuration value.

Parameters

  • $xKey โ€” Key of the key/value pair
  • [$retifempty]: Value to be returned in case the value of the key is not already set.

Returns

  • Mixed โ€” the stored value, or the supplied fallback.

Return example

$v = hardDefaultGet('INVOICE_PREFIX', 'INV');
// e.g. 'SO'

Usage example

$selected = hardDefaultGet( 'MASTER_CHILD', 'NO' );
returns: 'NO'

$selected = hardDefaultGet( 'MASTER_CHILD', 'YES', 'NO' ); // sets the YES value to the key
returns: 'YES'

:material-file-code: Source: apis/core2_a.php


localWord()

Prototype

LocalWord( $word, $langcode='' )

Description

  • Translates a word/phrase to a target language code (via Google), for regional UI.
  • Use to localise labels/messages to the project's configured language.

Parameters

  • $word โ€” Word or Phrase to be converted.
  • [$langcode]: Language Code. Defaults to User Selected Language.

Returns

  • String โ€” the translated word/phrase.

Return example

echo LocalWord('Welcome', 'hi');
// e.g. 'เคธเฅเคตเคพเค—เคค เคนเฅˆ'

Usage example

$converted_name = LocalWord( 'India', 'hi' );
returns: ??????

:material-file-code: Source: apis/core2_a.php


scr_Hide()

Prototype

scr_Hide($cVar)

Description

  • Instructs the browser to hide a form field.
  • Use for conditional UI driven by server-side logic.

Parameters

  • $cVar โ€” id / name of column / input variable on screen

Returns

  • Sends the hide instruction to the browser.

Return example

scr_Hide('discount');
// #discount# hidden

Usage example

scr_Hide( 'weight' );

:material-file-code: Source: apis/core2.php


scr_Show()

Prototype

scr_Show($cVar)

Description

  • Instructs the browser to show a (previously hidden) form field.
  • Companion to scr_Hide() for conditional fields.

Parameters

  • $cVar โ€” id / name of column / input variable on screen

Returns

  • Sends the show instruction to the browser.

Return example

scr_Show('discount');
// #discount# shown

Usage example

scr_Hide( 'weight' );

:material-file-code: Source: apis/core2.php


scr_getvalue()

Prototype

scr_getvalue($cVar)

Description

  • Reads the current value of a form field from the POSTed browser state by variable name.
  • Use inside server-side event/validation code to inspect what the user entered.

Parameters

  • $cVar โ€” id / name of column / input variable on screen

Returns

  • Mixed โ€” the field's current value, or null if absent.

Return example

$qty = scr_getvalue('qty');
// e.g. '10'

Usage example

$weight = scr_getvalue('weight');
$rate   = scr_getvalue('rate');

:material-file-code: Source: apis/core2.php


scr_message()

Prototype

scr_message( $messages='' )

Description

  • Sends a message from post-validation code to the client browser.
  • Use to surface validation feedback during data entry.

Parameters

  • $message โ€” Message / notice to be displayed on user screen

Returns

  • Sends the message to the browser (no meaningful return value).

Return example

scr_message('Rate cannot be zero');
// shown to the user

Usage example

scr_message( 'Lot Number Not Specified. Can Not Check Stock!' );

:material-file-code: Source: apis/core2.php


scr_setFocus()

Prototype

scr_setFocus($cVar)

Description

  • Instructs the browser to move focus to a specified field.
  • Use to guide the user to the next/erroneous input.

Parameters

  • $cVar โ€” id / name of column / input variable on screen

Returns

  • Sends the focus instruction to the browser.

Return example

scr_setFocus('rate');
// cursor jumps to #rate#

Usage example

scr_setFocus( 'weight' );

:material-file-code: Source: apis/core2.php


varSet()

Prototype

varSet( $cVar, $xValue, $execpostvalid=true )

Description

  • Pushes a value to the client browser to set a form field (server-driven field update).
  • Use in post-validation/event code to update on-screen inputs; can re-trigger post-validation.

Parameters

  • $cVar โ€” id / name of column / input variable on screen
  • $xValue โ€” value to be set into the input field

Returns

  • Nothing โ€” sends an instruction to the browser as a side effect.

Return example

varSet('amount', 1250.00);
// browser sets #amount# to 1250.00

Usage example

varSet('name', $row['name'] );
varSet('rate', $row['weight'] );

:material-file-code: Source: apis/core2.php


xDefault()

Prototype

xdefault( $xKey, $xValueSet='', $retifempty='' )

Description

  • Gets or sets a persistent project-level key/value. With only a key it reads; with a value it stores permanently.
  • Use for project configuration/feature flags that must survive across sessions.
  • Returns a fallback when the key is empty/unset.

Parameters

  • $xKey โ€” Key of the key/value pair
  • [$xValueSet]: Value to be set for this key. Optional. If not passed, the already set value is returned.
  • [$retifempty]: Value to be returned in case the value of the key is not already set.

Returns

  • Mixed โ€” the stored value for the key (or the provided default when unset).

Return example

xdefault('AUTO_EMAIL', 'YES');     // set
$v = xdefault('AUTO_EMAIL', '', 'NO'); // get -> 'YES'

Usage example

$selected = xDefault( 'MASTER_CHILD', '', 'NO' );
returns: 'NO'

$selected = xDefault( 'MASTER_CHILD', 'YES', 'NO' ); // sets the YES value to the key
returns: 'YES'

:material-file-code: Source: apis/core2_a.php


xDefault2()

Prototype

xdefault2( $xKey, $xValueSet='', $retifempty='' )

Description

  • Variant of the persistent project key/value store (xDefault) with the same get/set semantics.
  • Use where a separate default namespace/behaviour is needed.

Parameters

  • $xKey โ€” Key of the key/value pair
  • [$xValueSet]: Value to be set for this key. Optional. If not passed, the already set value is returned.
  • [$retifempty]: Value to be returned in case the value of the key is not already set.

Returns

  • Mixed โ€” the stored value (or default when unset).

Return example

$v = xdefault2('THEME', '', 'light');
// e.g. 'dark'

Usage example

$selected = xDefault2( 'MASTER_CHILD', '', 'NO' );
returns: 'NO'

$selected = xDefault2( 'MASTER_CHILD', 'YES', 'NO' ); // sets the YES value to the key
returns: 'YES'

:material-file-code: Source: apis/core2_a.php