after submitting a form to email i get 2 email instead 1

dmitriy

after submitting a form to email i get 2 email instead 1 how can i fix it? I need that only 1 letter come to email

js:

app.controller('threeCtrl',function($scope){
    $("#subBusinessOne").click(function() {
    var url = "businessFormOne.php"; 
    $.ajax({
               type: "POST",
               url: url,
               data: $("form#businessFormOne").serialize(), 
               success: function(data)
               {
                   var name = $("input[name=name]").val("");
                   var rel= $("input[name=phone]").val("");
               }
             });
    return false; // avoid to execute the actual submit of the form.
        });
    });

php:

<?php 
$ToEmail = 'myemail.com'; 
$EmailSubject = 'Охрана бизнес-обьектов'; 
$mailheader = "From: ".$_POST["email"]."\r\n";
$MESSAGE_BODY = "Имя: ".$_POST["name"].""; 
$MESSAGE_BODY .= "Телефон: ".$_POST["phone"].""; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>
Jakub Krawczyk

I guess that #subBusinessOne is a form submit button. You're sending an AJAX request and then submitting the form again as a normal HTTP request.

Instead of detecting button click event, you should check if the form has been submitted, then prevent default action and send the AJAX request. Your JS code would then look like this:

app.controller('threeCtrl',function($scope){
    $("#businessFormOne").submit(function(e) {

    e.preventDefault(); // this is to avoid the actual submit

    var url = "businessFormOne.php"; 
    $.ajax({
               type: "POST",
               url: url,
               data: $("form#businessFormOne").serialize(), 
               success: function(data)
               {
                   var name = $("input[name=name]").val("");
                   var rel= $("input[name=phone]").val("");
               }
             });
        });
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I prevent Git from using an email of the form username@pc-name instead of an empty one?

how to get email field of contact us form in the email which admin got (yii2)

I want to open modal after submitting form?

How do I get all form inputs and send them to an email?

How to get User Email who is submitting the form and save it

Trying to redirect in PHP after submitting an email form

How can I get the form values to appear in the table after submitting?

Email Value Validation Error when submitting form

How to get a popup box after submitting a form?

PHP contact form submitting but not receiving email

PHP form not submitting entries to email. I'm missing something

Regex Email with 2 characters after @

Submitting HTML form to email, not open mail

Email form not sending email

Get the check box value after submitting a form

send email after form submission

Send Email after form submission via email service such as Mailchimp

Unable to hold form 1 value after submitting form 2

I get a email without the form information, why?

How to validate email after the '.(dot)' while submitting form using Jquery Plugin

Unable to stop form from submitting when validating an email

Ruby on Rails - Submitting Email Form Newsletter to Mailchimp

How to send an email after User post the form?

Yii2 form validating but not submitting to send email

Submitting form item via code not triggering an email notification

Reload form if I get an error when validate email

How do I check users email isn't already in my database when submitting a form?

send email after filling a form

Sending email via SendGrid after form submission