cforms II User Forum

Registration is currently disabled.
Guest

FAQs

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
oliviercreacom
Guest

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
Oliver
Munich, Germany
Admin
Forum Posts: 6400
Member Since:
March 6, 2005
Offline

this is not possible with a file upload field.

October 22, 2012
9:30 am
oliviercreacom
Guest

I've tried in the page displaying the form :

var radiofield = 'cf_field_16';

var uploadfield = 'cf_uploadfile-17';

jQuery("input").click(function(){
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;
}
}
jQuery('form[id=cformsform]').submit(function(){
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:
28 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: 3712

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5310

Posts: 18671

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

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

Administrators: Oliver (6400), Nicky (3)