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])
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()
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>'); }