[pmwiki-devel] form elements with limited javascript events/functions

Peter Bowers pbowers at pobox.com
Tue Feb 22 13:31:18 CST 2011


I am working on a recipe that should allow certain javascript
functions to be enabled as input events but not others (for security
purposes).  In other words, I'd like onchange="foo()" or
onclick="foo()" to be valid, but I don't want onchange="bar()" to be
allowed.

I looked at this page:

http://www.pmwiki.org/wiki/Cookbook/InputFormsAndJavaScript

and I was able to create a custom set of input elements like this:

===(snip)===
foreach(array('text'=>'onchange', 'submit'=>'onclick',
    'password'=>'onchange', 'radio'=>'onchange', 'checkbox'=>'onchange',
    'reset'=>'onclick', 'image'=>'onclick') as $k=>$t)
  SDV($InputTags["ajax".$k][':html'], "<input type='$k'
$t=\"wshAjax()".($k=='submit'?'; return false;':'')."\"
\$InputFormArgs />");
===(snip)===

This allows something like this:

===(snip)===
(:input ajaxtext foo bar:)
===(snip)===

which uses the wshAjax() function on the event onchange.

However, this assumes (for instance) that text fields will always use
the onchange event and submit will always use onclick and there's no
flexibility to use a different event.

Any ideas how I can do this more flexibly (allowing a choice of
events) without copying a good portion of forms.php with slight
alterations?

-Peter



More information about the pmwiki-devel mailing list