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 
Mandatory field using client-side checking

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



Joined: 09 Aug 2007
Posts: 9

PostPosted: Tue Mar 04, 2008 5:30 am    Post subject: Mandatory field using client-side checking Reply with quote

I'm trying to make the user's phone number a mandatory field, but I'd like it to be a client-side alert, using a Javascript pop-up box, but using the code below I'm getting PHP displaying the error message instead of Javascript. Any idea what's I've done wrong?

Code:
// Home phone number
$home_areaCode = &HTML_QuickForm::createElement('text', '', null, array('size' => 3, 'maxlength' => 3));
$home_exchange = &HTML_QuickForm::createElement('text', '', null, array('size' => 3, 'maxlength' => 3));
$home_last4    = &HTML_QuickForm::createElement('text', '', null, array('size' => 4, 'maxlength' => 4));
$form->addGroup(array($home_areaCode, $home_exchange, $home_last4), 'h_number', 'Home Phone:', '-');
$form->addGroupRule('h_number', 'Please enter your home phone number', 'required', null, 'client');
[/code]
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1011

PostPosted: Tue Mar 04, 2008 5:37 pm    Post subject: Reply with quote

Are you using the default renderer? IIRC only this renderer outputs the necessary JavaScript code, with other renderery you have to care of outputting the code yourself.
Back to top
View user's profile Send private message
Leigh



Joined: 09 Aug 2007
Posts: 9

PostPosted: Wed Mar 05, 2008 2:16 am    Post subject: Reply with quote

Yes, I think I'm using the default renderer. See below.
Code:
  $renderer =& new HTML_QuickForm_Renderer_Tableless();
  $renderer->addStopFieldsetElements('submit');
  $form->accept($renderer);
  echo $renderer->toHtml();

I have other fields where the Javascript pop-up works, it doesn't seem to work with this one.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1011

PostPosted: Wed Mar 05, 2008 10:37 am    Post subject: Reply with quote

Leigh wrote:
Yes, I think I'm using the default renderer.


No, not really, but this renderer is also a very good choice. Wink
(I'm biased on this though ...)

Anyway, the problem seems to be that you've mixed up the parameters of addGroupRule(). 'client' should be the sixth, not the fifth parameter.
Back to top
View user's profile Send private message
Leigh



Joined: 09 Aug 2007
Posts: 9

PostPosted: Thu Mar 06, 2008 5:09 am    Post subject: Reply with quote

Ah, when you said "default renderer" I thought you meant yours.

And also you are right once again, moving the parameter to the sixth element worked. Thanks very much!
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