Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fix: fix contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
ratheesk committed Jan 20, 2024
1 parent eaf2f87 commit 1783a8f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
92 changes: 52 additions & 40 deletions assets/js/form-validate.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
function valid_datas( f ){

if( f.name.value == '' ){
jQuery('#form_status').html('<span class="wrong">Your name must not be empty!</span>');
notice( f.name );
}else if( f.email.value == '' ){
jQuery('#form_status').html('<span class="wrong">Your email must not be empty and correct format!</span>');
notice( f.email );
//}else if( f.phone.value == '' ){
//jQuery('#form_status').html('<span class="wrong">Your phone must not be empty and correct format!</span>');
//notice( f.phone );
}else if( f.subject.value == '' ){
jQuery('#form_status').html('<span class="wrong">Your subject must not be empty!</span>');
notice( f.subject );
}else if( f.message.value == '' ){
jQuery('#form_status').html('<span class="wrong">Your message must not be empty!</span>');
notice( f.message );
}else{
jQuery.ajax({
url: 'mail.php',
type: 'post',
data: jQuery('form#fruitkha-contact').serialize(),
complete: function(data) {
jQuery('#form_status').html(data.responseText);
jQuery('#fruitkha-contact').find('input,textarea').attr({value:''});
jQuery('#fruitkha-contact').css({opacity:1});
jQuery('#fruitkha-contact').remove();
}
});
jQuery('#form_status').html('<span class="loading">Sending your message...</span>');
jQuery('#fruitkha-contact').animate({opacity:0.3});
jQuery('#fruitkha-contact').find('input,textarea,button').css('border','none').attr({'disabled':''});
}

return false;
function valid_datas(f) {
if (f.name.value == '') {
jQuery('#form_status').html(
'<span class="wrong">Your name must not be empty!</span>'
);
notice(f.name);
} else if (f.email.value == '') {
jQuery('#form_status').html(
'<span class="wrong">Your email must not be empty and correct format!</span>'
);
notice(f.email);
//}else if( f.phone.value == '' ){
//jQuery('#form_status').html('<span class="wrong">Your phone must not be empty and correct format!</span>');
//notice( f.phone );
} else if (f.subject.value == '') {
jQuery('#form_status').html(
'<span class="wrong">Your subject must not be empty!</span>'
);
notice(f.subject);
} else if (f.message.value == '') {
jQuery('#form_status').html(
'<span class="wrong">Your message must not be empty!</span>'
);
notice(f.message);
} else {
jQuery.ajax({
url: 'mail.php',
type: 'post',
data: jQuery('form#dow-contact').serialize(),
complete: function (data) {
jQuery('#form_status').html(data.responseText);
jQuery('#dow-contact').find('input,textarea').attr({ value: '' });
jQuery('#dow-contact').css({ opacity: 1 });
jQuery('#dow-contact').remove();
},
});
jQuery('#form_status').html(
'<span class="loading">Sending your message...</span>'
);
jQuery('#dow-contact').animate({ opacity: 0.3 });
jQuery('#dow-contact')
.find('input,textarea,button')
.css('border', 'none')
.attr({ disabled: '' });
}

return false;
}

function notice( f ){
jQuery('#fruitkha-contact').find('input,textarea').css('border','none');
f.style.border = '1px solid red';
f.focus();
}
function notice(f) {
jQuery('#dow-contact').find('input,textarea').css('border', 'none');
f.style.border = '1px solid red';
f.focus();
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ <h2>Have you any question?</h2>
</div>
<div id="form_status"></div>
<div class="contact-form">
<form type="POST" id="fruitkha-contact" onSubmit="return valid_datas( this );">
<form type="POST" id="dow-contact" onSubmit="return valid_datas( this );" action="mail.php">
<p>
<input type="text" placeholder="Name" name="name" id="name">
<input type="email" placeholder="Email" name="email" id="email">
Expand Down
2 changes: 1 addition & 1 deletion mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$body = ob_get_contents();
ob_end_clean();

$to = '[email protected]';
$to = '[email protected]';

$s = mail($to, $subject, $body, $headers, "-t -i -f $from");

Expand Down

0 comments on commit 1783a8f

Please sign in to comment.