Skip Navigation

[Resuelto] required error appears in cred frontend dispite fulfilled requirement

This support ticket is created hace 6 años, 5 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 9 respuestas, tiene 2 mensajes.

Última actualización por Nigel hace 6 años, 5 meses.

Asistido por: Nigel.

Autor
Mensajes
#911527

Hey,

take a look here:

enlace oculto

when editing the play, try to add some text to the "play description", then scroll to the bottom and press save.
the error that popsup is that you need to check at leaset 1 genre - but there are already a few genres checked.

any ideas?

thanks!

#911593

update: after updating toolset plugins and wpml plugins + unlocking cred form in wpml settings as "translatable" - error is gone.

#911602

nope - it now just sometimes works and sometimes doesn't. very confusing.

#911725

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Ido

I visited the link.

To see the problem I should be editing this post with a Toolset Form, is that right?

I presumably need access credentials to edit the posts, let me mark your next reply as private so you can provide them.

You say it sometimes works and sometimes doesn't. Do you have a specific post where it consistently doesn't work?

#911808

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Ido

You are using some custom code to make the genre taxonomy required, would that be right?

What/where is it?

#911817

hey,
all code is in functions.php
i think the relevant code starts in line 378
thanks!
ido

#912180

hey again,

sorry - validation code is in:

\library\js\scripts.js:

 	/*************play forms validation**************/
	jQuery('#cred_form_1964_1, #cred_form_1971_1').submit(function(){
		return validateForm();
	});
	validateForm=function() {
	
		var genreFlag = false;
		var premiereFlag = false;
		var charactersFlag = false;
		
		jQuery('#cred_form_1964_1_wpcf-total_select option, #cred_form_1971_1_wpcf-total_select option').each(function(){
			if(jQuery(this).attr('selected')) {
				//alert(jQuery(this).text())
				if(jQuery(this).text()!='none') {
					charactersFlag = true;
				}
			}
					
		})
		if(jQuery('#cred_form_1964_1_wpcf-never-produced_1, #cred_form_1971_1_wpcf-never-produced_1').attr('checked') == 'checked' || jQuery('#cred_form_1964_1_wpcf-premiere-year, #cred_form_1971_1_wpcf-premiere-year').val()!="") {
			premiereFlag = true;
		}
		jQuery('#cred_form_1964_1_genre input[type=checkbox], #cred_form_1971_1_genre input[type=checkbox]').each(function(){
			if(jQuery(this).attr('checked')) 
				genreFlag=true; 
			})
			
			
		if(!premiereFlag) {
			alert('אנא מלא את שנת הבכורה או סמן את תיבת "לא הופק מעולם"');
			return false;
		} else if(!genreFlag) {
			alert("אנא סמן תיבת סימון אחת לפחות בקטגוריית הז'נר");
			return false;
		} else if(!charactersFlag) {
			alert("אנא בחר את מספר הדמויות");
			return false;
		} else {
			
			return true;
		}
	}
	if(location.pathname=="/add-play-form/" || location.search=="?cred-edit-form=1964") {
		jQuery(window).bind('beforeunload', function(){
			var valid = validateForm();
		    if(!valid && (location.search == "?cred-edit-form=1964" || location.pathname == "/add-play-form/")){
		        return "לא כל שדות החובה מולאו, והמחזה לא יתעדכן/יתווסף. האם את/ה בטוח/ה שאת/ה רוצה לעזוב את העמוד?"
		    } else {
		    	jQuery(window).unbind('beforeunload')
		    }
		});
	} else {
		jQuery(window).unbind('beforeunload');
	}
 	/*************END form validation**************/

Thanks!

#912230

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Ido

Sorry, I can't debug your custom JavaScript for you.

We have an API for form validation, and you can make taxonomies required by adding code such as the following to your theme's functions.php file:

function tssupp_require_genre($field_data, $form_data) {
  
    // Split $field_data into separate $fields and $errors
    list( $fields,$errors ) = $field_data;
       
    // validate specific form
    if ( $form_data['id'] == 123 ) {
   
        // check if genre taxonomy set
        if ( empty( $fields['genre']['value'] ) ) {
  
            $errors['genre'] = 'You must select a genre';
        }        
     }
    return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_genre', 10, 2 );

Edit the form ID and the taxonomy slug as required.

If you can't get your JS solution to work I suggest you go with our API method.

#912242

thanks Nigel 🙂

ok - will do. should I use the same function for other custom fields validation?

Ido

#912243

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

You can bundle all of the validation for the same form into a single function, for taxonomies and for custom fields.

I'd suggest you error log $fields and $errors and $form_data so that you can see what it is you are working with.