ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Dynamic required

tobajarrat1 18 Nov, 2012
Hi forum users!

I have a form where some fields are required, dependent on a dropdown i disable these fields.
These fields are in a <div> container.

But when I submit the form and get the email, the disabled field inputs are not empty, but have brackets like {input_4}.
How can i prevent this behavior?

This is my code..
window.addEvent('domready', function() {
  var myVerticalSlide = new Fx.Slide('adresse');
  var mySonstigeSlide = new Fx.Slide('sonstige_container_div');
 $('anliegen').addEvent('change', function() {
  if ($('anliegen').value == 'Bestellung' || $('anliegen').value == 'Versand' ) {
   $$('#adresse input').each(function(item){
 item.disabled   = false; });
  myVerticalSlide.slideIn();
   } else {
$$('#adresse input').each(function(item){
 item.disabled   = true; });
 myVerticalSlide.slideOut();
}
if ($('anliegen').value == 'Sonstige Fragen') {
   $('sonstige').disabled = false;
    mySonstigeSlide.slideIn();
   } else {
 $('sonstige').disabled = true;
    mySonstigeSlide.slideOut();
 }
 });
  if ($('anliegen').value == 'Bestellung' || $('anliegen').value == 'Versand' ) {
   $$('#adresse input').each(function(item){
 item.disabled   = false; });
  myVerticalSlide.show();
} else {
$$('#adresse input').each(function(item){
 item.disabled   = true; });
  myVerticalSlide.hide();
}
if ($('anliegen').value == 'Sonstige Fragen') {
   $('sonstige').disabled = false;
    mySonstigeSlide.show();
} else{
 $('sonstige').disabled = true;
  mySonstigeSlide.hide();
}
});

I read something about "addClass("validate['required']") and formcheck.register" but i dont know how to implement?!
please can somebody help me with this?
GreyHead 18 Nov, 2012
Hi tobajarrat1,

This happens no entry for e.g. input_4 in the $form->data array. When you disable the input this will happen.

The simplest fix is probably to add a 'ghost' hidden input* with the same name at the beginning of the Form HTML. If the 'real' input has a value this will over-write the ghost, if it's disabled then the ghost value will be used. (Alternatively you can check the results after submission and add ghost values using PHP in a Custom Code action).

Bob

* If you use the ChronoForms Wizard to add elements these have a built-in 'ghost' option that is set on by default.
tobajarrat1 18 Nov, 2012
thank you a lot!
i thought the hidden field will avert the submission because the same field name is required. now i understand the required tag works with the ids not with the field names!
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com