|
Cookbook /
InputFormsAndJavaScriptSummary: Some ideas of combining Javascript with PmWiki Input forms
Version:
Prerequisites:
Status:
Maintainer:
Categories: Forms
Questions answered by this recipeHow can my javascript add values to input forms, for further processing in php? DescriptionFor developers Some ideas of combining javascript with PmWiki Input forms. The important part is to define PmWiki's scripts/forms.php defines the default If your wiki is safe enough, you can define customised versions of the include_once('scripts/forms.php');
$InputAttrs[] = 'onclick';
$InputAttrs[] = 'onsubmit';
Note that scripts/forms.php needs to be called first. With this change you armed any input markup to execute any kind of javascript!! If you wish to be safe, you could restrain from this general addition of event handlers, and define a custom input control instead, with the precise javascript calls you need. $InputTags['myform'] = array(
':args' => array('action', 'method'),
':html' => "<form \$InputFormArgs onsubmit='return checkInput(this)'>",
'method' => 'post');
Then use markup Example:Add this to config.php, which will be inserted in the page head as javascript: $HTMLHeaderFmt['javascripttest'] = "
<script type='text/javascript'>
function readText (form) {
TestVar =form.inputbox.value;
alert (\"You typed: \" + TestVar);
return false;
}
function writeText (form) {
form.inputbox.value = \"Have a nice day!\"
return false;
}
</script>
";
Then create a wiki page with this markup: (:input form "{$PageUrl}" :)
Enter something in the box:\\
(:input text inputbox "":)\\
(:input submit button1 "Read" onclick="return readText(this.form)":)
(:input submit button2 "Write" onclick="return writeText(this.form)":)
(:input end:)
You see two onclick event handlers, each calling a javascript function. The first takes a value from the input text box named "inputbox". The second writes a value into this box. Using named controls creates the bridge to javascript. Note also the use of 'return' in the javascript: I translated the example for PmWiki markup from "Using JavaScript and forms" HansB July 14, 2008, at 11:06 AM NotesRelease Notes
See AlsoContributorsComments |