/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
QF - conditional elements requiring condit~
Fra : Tommy Ipsen


Dato : 15-04-04 16:13

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

 
 
Søg
Reklame
Statistik
Spørgsmål : 177559
Tips : 31968
Nyheder : 719565
Indlæg : 6408929
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste