Quickform submit button types
| From: | Mike Carter | Date: | Thu, 28 Aug 2003 10:09:15 +0000 |
| Subject: | Quickform submit button types | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-7443@lists.php.net to get a copy of this message | ||
I've just done a little experiment with Quickform. My form contains a
field which *requires* a value before it can be submitted. Not entering
anything pops up a javascript alert box. On this form I also have a
cancel button to exit the form, upon clicking "cancel" it displays a
confirmation message box in javascript.
Using an element type 'button' this works great, I defined the element
as below...
$actions[] = &HTML_QuickForm::createElement('button', 'action',
$language['L_ButtonCancel'], array("onClick" =>
"if(window.confirm('".$language['L_CancelApplication']."')){
window.location.href='index.php';}"));
However, wanting to make my form look a little more jazzy I tried to
replace the cancel button with an image element - however the javascript
doesn't quite work as expected here. I define the element as below...
$actions[] = &HTML_QuickForm::createElement('image', 'action',
$GLOBALS['smarty']->get_template_vars('imagePath').'buttons/cancel.jpg',
array("onClick" =>
"if(window.confirm('".$language['L_CancelApplication']."')){
window.location.href='index.php';}"));
However, this time I get my cancel confirmation alert box - then - I get
the validation error alert box, after clicking 'ok' to the validation
error box I get redirected to the cancel page (ie. "index.php").
Can anybody explain to me why there is the difference and what, if
anything, I can do to prevent the image element for doing what it does.
Thanks in advance,
--
Mike Carter
[Senior Web Developer]
Personal Medical Advisor Limited
T: 0161 927 2330 | F: 0161 928 2932 | W:
www.personalmedicaladvisor.co.uk