| View previous topic :: View next topic |
| Author |
Message |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Tue Jul 15, 2008 12:24 pm Post subject: Cancel Button |
|
|
Hi Guys
How can I achieve a cancel button??? If I put another submit button and call it cancel it will try to run the client validation and get stucks.
So for the moment I put another button called cancel which includes some javacode:
| Code: |
$aButtons[] = &HTML_QuickForm::createElement('button', 'btnCancel', 'Cancel', "onClick=\"window.location.href='" . $sPag_Name . "'\"");
|
But I don't like the solution much because if the client has the javascript switched off it won't run. Is there a better solution?
Thx[/code] |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1003
|
|
| Back to top |
|
 |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Wed Jul 16, 2008 2:32 am Post subject: |
|
|
Hi Mark
But that is what I'm actually doing in the code above. I use a normal button with some javascript. I probably have to create a second form for the cancel button withouth any validation or is there another solution?
Thx |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1003
|
Posted: Wed Jul 16, 2008 4:13 pm Post subject: |
|
|
| SanderK wrote: | | But that is what I'm actually doing in the code above. I use a normal button with some javascript. I probably have to create a second form for the cancel button withouth any validation or is there another solution? |
Sorry, I've read your post too quickly and I also had something wrong in mind about the normal buttons.
If you don't want to use a simple link (<a href="...">...</a>), I'd define a second submit button with a unique name (like "cancel"). In your code, you could check whether the form was submitted (if ($form->isSubmitted())), and react then accordingly to submitted name (either "submit" (=> validation) or "cancel"). I haven't tested this, but it should work. |
|
| Back to top |
|
 |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Mon Jul 21, 2008 2:16 pm Post subject: |
|
|
| This won't work because there is client validation going on. Let's say there is a textfield which is required. Unless the user writes something in that textfield he won't be able to use the cancel button. Do you see the problem? Anyway I use a simple script in javascript to go back for the moment. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1003
|
Posted: Mon Jul 21, 2008 5:48 pm Post subject: |
|
|
| SanderK wrote: | | This won't work because there is client validation going on. Let's say there is a textfield which is required. Unless the user writes something in that textfield he won't be able to use the cancel button. Do you see the problem? Anyway I use a simple script in javascript to go back for the moment. |
The easiest way would still be a simple link -- no problems with validation and no problems with requiring JS.
The more complicated solution with the cancel button would be to move the onsubmit event from the <form> tag to the <input type="submit> tag, e.g. with regexps after calling $form->toHtml(). Overloading the QF class should also be possible. |
|
| Back to top |
|
 |
|