cforms II User Forum

Registration is currently disabled.


Login form protected by Login LockDown.

Lost password?
Advanced Search

— Forum Scope —


— Match —


— Forum Options —


Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
How to have mandatory field depending on another field
October 18, 2012
4:02 pm

I'd like to to if it is  possible \"out-of-the-box\" (without big hacking), to have a mandatory field dependant of a previous selection in the form :

I explain with my case :

I have a radiobutton field \"Send your drawing\" with 2 cases : – by fax, -by mail

If the client selects by mail, he would have to submit a file (mandatory), but if he selects by fax, the file shouldn't be mandatory to be sent.

So how to achieve that ?


Thanks in advance

October 21, 2012
7:13 pm
Munich, Germany
Forum Posts: 6400
Member Since:
March 6, 2005

this is not possible with a file upload field.

October 22, 2012
9:30 am

I've tried in the page displaying the form :

var radiofield = 'cf_field_16';

var uploadfield = 'cf_uploadfile-17';

if (jQuery('input[type=submit]')
&& jQuery('input[type=radio][name='+radiofield+']:checked').val() == 'mail'
&& jQuery('#'+uploadfield)[0].value == ''){
var text = jQuery('#usermessageb span').text();
if (text.indexOf("upload a file") < 0){
jQuery('#usermessageb span').html(text+"<br />Please upload a file");
return false;
console.log('Submit blocked!');
return false;

This adds a message "Please upload a file" at the end of the warning if i don't choose a file when the file radiobutton is checked, but the form is still sent, even without the file : the ajax stuff of cforms overrides this because the file is not checked mandatory in the admin.

Can't we override or bypass the js for this part ?

Forum Timezone: Europe/Berlin

Most Users Ever Online: 959

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

tracedef: 43

mores: 21

Gyrus: 20

frozenwaste: 18

asuffredini: 15

photoworks: 14

Member Stats:

Guest Posters: 3762

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5361

Posts: 18742

Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass

Moderators: Paul (421), cnymike (8), sonika (95)

Administrators: Oliver (6400), Nicky (3)