Extend a small ajax contactform with a checkbox

Hi,
i need help to extend a small ajax contactform with one checkbox (required).

Best regards,
Roland

Hi,

sorry! not clear your query. If you want to add a checkbox in your form then you can use input type=“checkbox”. you can get help from google search. and customize your ajax functionality and php based on the checkbox field.

Thanks

Hi,
thanks for your reply.

Here is the code in HTML:

Ich habe die Datenschutzerklärung gelesen und akzeptiere sie hiermit.

In js i use this:

function buildify_tm_contact_form(){

"use strict";

jQuery(".contact_form #send_message").on('click', function(){
	
	var name 		= jQuery(".contact_form #name").val();
	var email 		= jQuery(".contact_form #email").val();
	var message 	= jQuery(".contact_form #message").val();
	var datenschutz 	= jQuery(".contact_form #datenschutz").val();
	var subject 	= jQuery(".contact_form #subject").val();
	var success     = jQuery(".contact_form .returnmessage").data('success');

	jQuery(".contact_form .returnmessage").empty(); //To empty previous error/success message.
	//checking for blank fields	
	if(name===''||email===''||message===''||datenschutz==='false'){
		
		jQuery('div.empty_notice').slideDown(500).delay(2000).slideUp(500);
	}
	else{
		// Returns successful data submission message when the entered information is stored in database.
		jQuery.post("modal/contact.php",{ ajax_name: name, ajax_email: email, ajax_message:message, ajax_datenschutz: datenschutz, ajax_subject: subject}, function(data) {
			
			jQuery(".contact_form .returnmessage").append(data);//Append returned message to message paragraph
			
			
			if(jQuery(".contact_form .returnmessage span.contact_error").length){
				jQuery(".contact_form .returnmessage").slideDown(500).delay(2000).slideUp(500);		
			}else{
				jQuery(".contact_form .returnmessage").append("<span class='contact_success'>"+ success +"</span>");
				jQuery(".contact_form .returnmessage").slideDown(500).delay(4000).slideUp(500);
			}
			
			if(data===""){
				jQuery("#contact_form")[0].reset();//To reset form fields on success
			}
			
		});
	}
	return false; 
});

}

Problem: The checkbox should be a required field.
Thanks for your help!

Hope datenschutz is checkbox. you used:
var datenschutz = jQuery(".contact_form #datenschutz").val();
try with this:
var datenschutz = $(‘input[name=datenschutz]:checked’).val();

and if condition use as like this
if(datenschutz)

Thanks

Hi,
now i have tested the new code.
It doesn`t work.

Is it possible to the send you a E-Mail with my FTP-Login?

Regards, Roland

Hi

Sorry! in forum we can give you guideline but for getting direct support you have to contact your purchased Item Author or hire a freelancer.
Is your form checkbox field name=“datenschutz”, you have to change my code accoeding to field name.

Thanks

Hi, thanks.

The author doesnt extend the form. I thought i find a freelander here.

The form works, only the verification checkbox on/off is the problem.

Here is the test-site: https://website-preview.de/kontakt.html

The code on HTML-Site:
Ich habe die Datenschutzerklärung gelesen und akzeptiere sie hiermit.

in js:
function buildify_tm_contact_form(){

"use strict";

jQuery(".contact_form #send_message").on('click', function(){
	
	var name 		= jQuery(".contact_form #name").val();
	var email 		= jQuery(".contact_form #email").val();
	var message 	= jQuery(".contact_form #message").val();
	var datenschutz = $("input[name=datenschutz]:checked").val();
	var subject 	= jQuery(".contact_form #subject").val();
	var success     = jQuery(".contact_form .returnmessage").data('success');

	jQuery(".contact_form .returnmessage").empty(); //To empty previous error/success message.
	//checking for blank fields	
	if(name===''||email===''||message===''||datenschutz==='false'){
		
		jQuery('div.empty_notice').slideDown(500).delay(2000).slideUp(500);
	}
	else{
		// Returns successful data submission message when the entered information is stored in database.
		jQuery.post("modal/contact.php",{ ajax_name: name, ajax_email: email, ajax_message:message, ajax_datenschutz: datenschutz, ajax_subject: subject}, function(data) {
			
			jQuery(".contact_form .returnmessage").append(data);//Append returned message to message paragraph
			
			
			if(jQuery(".contact_form .returnmessage span.contact_error").length){
				jQuery(".contact_form .returnmessage").slideDown(500).delay(2000).slideUp(500);		
			}else{
				jQuery(".contact_form .returnmessage").append("<span class='contact_success'>"+ success +"</span>");
				jQuery(".contact_form .returnmessage").slideDown(500).delay(4000).slideUp(500);
			}
			
			if(data===""){
				jQuery("#contact_form")[0].reset();//To reset form fields on success
			}
			
		});
	}
	return false; 
});

}

Thanks for your further help!

you can try to replace the code:
if(name===’’||email===’’||message===’’||datenschutz===‘false’){

with

if(!name || !email || !message || !datenschutz){

Wow! Perfect!
Thank you so much for your help!

How can I show my appreciation?

Roland

1 Like

you got solved and you are happy. This is enough for us. Much appreciated. Thanks