Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 2.04 KB

File metadata and controls

63 lines (41 loc) · 2.04 KB

PHP: How to pass data to a PHP Procedure

nuRunPHPHidden() runs a Procedure on the server that contains PHP code. To pass data to the procedure, use nuSetProperty(). This sets the current Form's property and is retrieved as a Hash Cookie when the Procedure runs.

  1. First, create a Procedure: Tab Builders -> Procedure -> Add if you don't have one at hand.

  2. Code: e.g. Procedure_Test

  3. Description: Enter a description for the procedure (E.g. Testing )

  4. Paste this PHP code

// Retrieve a single hash cookie (see Example 1)
$param = "#param#"; // 'test single parameter'

// Retrieve a hash cookie that contains multiple data (see Example 2)
$params = json_decode(base64_decode('#params#'));

$info1 = $params->info1; // 'a'
$info2 = $params->info2; // 'b'
$info3 = $params->info3; // 'c'
  1. Save

  2. Add this JavaScript Code to your form’s Custom Code field:

How to add Custom Code

function base64encode(str) {
	let encode = encodeURIComponent(str).replace(/%([a-f0-9]{2})/gi, (m, $1) => String.fromCharCode(parseInt($1, 16)))
	return btoa(encode)
}

function runPHPHiddenWithParams(procedure, params) {
	nuSetProperty('params', base64encode(JSON.stringify(params)));
	nuRunPHPHidden(procedure, 1);
}

Example 1: Passing a single value

Create a Button with a custom click event to run the Procedure Procedure_Test. At the same time the property param with value 'test single parameter' is set.

nuSetProperty('param', 'test single parameter'); nuRunPHPHidden('Procedure_Test', 1);

Example 2: Passing multiple data

Create a Button with a custom click event to run the Procedure Procedure_Test. Multiple "parameters" are passed to the Procedure.

runPHPHiddenWithParams('Procedure_Test', {info1: 'a', info2: 'b', info3: 'c'});