Translations of this page:
 

buttonDataCode() and buttonDataGet()

The two functions buttonDataCode() and buttonDataGet() allow buttons to be placed on a questionnaire page which repeat the current page and can trigger functions there.

The buttonDataCode() function creates a button, stores data and returns the HTML code for the button.

string buttonDataCode(string content, [mixed data], [array|string CSS-class])

  • contentHTML code to be displayed as the content of the button.
  • data – Data to be stored for the button, e.g. a number, text or an array.
  • CSS-class – One or more CSS classes to be used for the button.

The buttonDataGet() function checks whether a button created with buttonDataCode() has previously been pressed and returns the data stored for it. If no data was hit or if no button was pressed, the function returns NULL.

mixed buttonDataGet()

Example

In this example, the button simply passes the string “again”. If the page is therefore repeated, the PHP code counts up a internal variable IV01_01 and shows a different question on the page depending on the variable.

// Check current counter,
// the (int) ensures that a 0 is sent on the first call,
// the 'code:ifany' suppresses a warning on the first call
$number = (int)value('IV01_01', 'code:ifany');
 
// increment the number if necessary and update the internal variable
$data = buttonDataGet();
if ($data == 'again') {
 $number = $number + 1;
 put('IV01_01', $number);
}
 
// Display question - depending on the number
// (the entries in the array have the indices 0 to 4)
$questions = [
 'AB01',
 'AB02',
 'AB03',
 'AB04',
 'AB05'
];
question($questions[$number]);
 
// Include button on the page - but only if there are still questions left
if ($number < count($questions) - 1) {
 $htmlButton = buttonDataCode('Next question', 'again');
 html('<div style="margin: 1em 0; text-align: center;">'.$htmlButton.'</div>');
}
en/create/functions/buttondatacode.txt · Last modified: 09.04.2024 16:23 by lukas.kraiger
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki