 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Leigh
Joined: 09 Aug 2007 Posts: 9
|
Posted: Tue Mar 04, 2008 5:30 am Post subject: Mandatory field using client-side checking |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Tue Mar 04, 2008 5:37 pm Post subject: |
|
|
| 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 |
|
 |
Leigh
Joined: 09 Aug 2007 Posts: 9
|
Posted: Wed Mar 05, 2008 2:16 am Post subject: |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Wed Mar 05, 2008 10:37 am Post subject: |
|
|
| Leigh wrote: | | Yes, I think I'm using the default renderer. |
No, not really, but this renderer is also a very good choice.
(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 |
|
 |
Leigh
Joined: 09 Aug 2007 Posts: 9
|
Posted: Thu Mar 06, 2008 5:09 am Post subject: |
|
|
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 |
|
 |
|
|
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
|
|