formChecker method
Generates a form checker hidden input field or a random key for form validation.
name
- The name attribute for the hidden input field. Defaults to 'formChecker'.
inputHtml
- A flag indicating whether to return the HTML input element. Defaults to true.
Returns a String containing either the HTML input field or the random key.
Implementation
String formChecker({String? name, bool inputHtml = true}) {
name = name ?? 'formChecker';
final key = generateRandomString();
var res = '<input type="hidden" name="$name" value="$key" />';
addSession(
name,
{
'key': key,
'time': DateTime.now().millisecondsSinceEpoch,
},
);
return inputHtml ? res : key;
}