Re: Quickform submit button types

From: Date: Thu, 28 Aug 2003 11:39:30 +0000
Subject: Re: Quickform submit button types
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-7444@lists.php.net to get a copy of this message
<mikeatwork@ukonline.co.uk> wrote : > 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, Hi Mike, Image element submits forms. Submit element submits forms. Button element does not submit forms. Your cancel element should be a button if you use javascript validation because validation is called with onSubmit event or you can replace it by a standard html img and a link (use a static element then). HTH Bertrand Mansion Mamasam

« previous php.pear.general (#7444) next »