PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Cancel Button

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML
View previous topic :: View next topic  
Author Message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Tue Jul 15, 2008 12:24 pm    Post subject: Cancel Button Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1013

PostPosted: Tue Jul 15, 2008 6:46 pm    Post subject: Reply with quote

How about using a simple link or a "normal" button? Both are supported by QF:
http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-button.php
http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-link.php
Back to top
View user's profile Send private message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Wed Jul 16, 2008 2:32 am    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1013

PostPosted: Wed Jul 16, 2008 4:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Mon Jul 21, 2008 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1013

PostPosted: Mon Jul 21, 2008 5:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software