QF - conditional elements requiring conditional rules!
| From: | Tommy Ipsen | Date: | Thu, 15 Apr 2004 15:43:22 +0000 |
| Subject: | QF - conditional elements requiring conditional rules! | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-11863@lists.php.net to get a copy of this message | ||
Hi
I have the following form fields generated by QuickForm:
<select onchange="this.form.url_manual.disabled=this.selectedIndex!=0;" name="url_automatic">
<option value="none">Ekstern side</option>
<option value="url1">Link to URL1</option>
<option value="url2">Link to URL2</option>
<option value="url3">Link to URL3</option>
</select>
<input value="Type URL" onchange="this.form.url_automatic.disabled=(this.value!='' && this.value!=this.defaultValue);" name="url_manual" type="text" />
These two fields are mutually exclusive meaning that either you choose an option from the drop-down menu or you type in a value in the text field.
Now I want to add a crude validation to the text field helping the user to type in a correct URL and I've reached the following:
$form->registerRule('url', 'regex', '/(^(ldap|http|https|ftp):\/\/(([a-z0-9\-\.]+\.+[a-z]{2,6})|([0-9]{1,3}\.){4})(\]?)$)/');
But the problem is that an URL is ONLY required IF the first/default option from the drop-down menu is active - if any other element is chosen, the text field is disabled and the rule shouldn't trigger!
How can I accomplish this behaviour using QuickForm?
Regards,
Tommy Ipsen