0

I'm trying to collect errors from js and send to email, but I'm not receving any email upon form submission. Here's my code:

<form id="vm-user-form" class="pure-form pure-form-aligned vm-user-form form-horizontal">
    <div class="vm-modal-body">
        <h4>Please provide us with these details.</h4>
        <fieldset class="form-group">
            <!-- <div class="pure-control-group"> -->
            <label for="username">Name:</label>
            <input id="vm-username" class="pure-input-1" name="username" type="text" placeholder="Your Names" pattern="[\w]{3,20}(\s)?[\w]{3,20}" title="eg. John Don" aria-required="true" required>
            <!-- </div> -->
            <!-- <div class="pure-control-group"> -->
            <label for="phoneno">Phone Number:</label>
            <input id="vm-phoneno" class="pure-input-1" name="phoneno" type="text" placeholder="Your Phone No." pattern="^(\+)?[\d]{6,14}$" title="eg. 0203001575, 023001575" aria-required="true" required>
            <!-- </div> -->
            <!-- <div class="pure-control-group"> -->
            <label for="email">Email Address:</label>
            <input id="vm-email" class="pure-input-1" name="emailaddress" type="email" placeholder="example-name@gmail.com" aria-required="true" required>
            <!-- </div> -->
            <!-- <div class="pure-controls">
                <button type="submit" class="pure-button pure-button-primary">Submit</button>
                </div> -->
        </fieldset>
    </div>
    <div class="vm-modal-footer">
        <!-- <div class="pure-controls"> -->
        <button type="button" class="vm-close-form hide pure-button button-danger" data-dismiss="modal">Close</button>
        <button type="submit" id="vm-submit-btn" class="pure-button button-vm">Submit</button>
        <!-- </div> -->
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
    </div>
</form>

Below is the Javascript code that is supposed to work with the Html code.

JavaScript:

 var politeErrorResponse = function(reason) {
        var waitToLoad = setTimeout(function() {
            // Save the details for later use
            status.reason = reason;

            // Load up the form
            $('.vm-popup-form').on('hidden.bs.modal', function(e) {
                // do something...
                // $('.vm-popup-form').modal('toggle');
                // alert("previous modal hidden.");
                $(".vm-close-form").show(300).addClass("hide").next().show(300);
            });

            $('.vm-popup').parent().load(chrome.extension.getURL('resources/view/form.html'), function() {
                $('.vm-popup-form').modal('toggle')

                $("#vm-user-form").on("submit", function(event) {
                    // prevent default form submit
                    event.preventDefault();
                    if ($('#vm-username').attr('value') != "" && $('#vm-phoneno').attr('value') != "" && $('#vm-email').attr('value') !== "") {
                        // reason carries the following:
                        // reason = ["caught", "isPostFunction", "responseText", "part_html"];

                        // On ERROR collect these DATA
                        var errorDetails = {
                            "username": $('#vm-username').attr('value'),
                            "phoneno": $('#vm-phoneno').attr('value'),
                            "emailaddress": $('#vm-email').attr('value')
                        }

                        // add this data to reason
                        $.extend(true, errorDetails, status.reason);
                        console.log(errorDetails);

                        $('.vitumob-popup-form .vm-modal-body').html(function() {
                            // Submit the details and error, and return Response
                            submitErrors(errorDetails, errorDetails.isPostFunction);
                            $(".vm-close-form").hide(300).removeClass("hide").next().fadeToggle().prev().show(300).on("click", function() {
                                // $('.vm-modal').modal("hide");
                                document.getElementById("vitumob-user-form").submit();
                            });
                            return '<h2> Your order has been submitted. We shall contact you. Thank you.</h2>'
                        })
                    } else {
                        // Focus on the 1st input
                        $('#vm-username').focus();
                    }

                });
                // alert("triggered the loading of the form");
            });
        }, 3000);

        // Cancel the submission of the form
    }

Please Help.

Alexander Mikhalchenko
  • 4,525
  • 3
  • 32
  • 56
Carol Kariuki
  • 95
  • 1
  • 1
  • 8
  • Please provide a [mcve]. You are missing some essential information, for example the method `submitErrors()`. Also I assume you have some server-side script to send the mail? Because as far as I know, Javascript can not send e-mail by itself. – Ivar Feb 09 '16 at 09:45
  • I don't have any serverside script.... I do have the method submitErrors() – Carol Kariuki Feb 09 '16 at 09:47
  • Well, [Javascript can't send email by itself](http://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript). You need to send it either by your own server-side script, a third party's server side script, or through the mail client by opening a `mailto:` url. – Ivar Feb 09 '16 at 09:52
  • I added this,
    should this work?
    – Carol Kariuki Feb 09 '16 at 09:57
  • No. If you wan't to use the mailto, then you should open it as a link. This will open the mail client of the user. They still need to send it themselves. At the point in your code where it should send it, you should use something like this: `window.location = "mailto:email@mail.com?subject=[url-encoded subject]&body=[url-encoded body]";` – Ivar Feb 09 '16 at 10:04
  • Alright, thanks. let me try that. – Carol Kariuki Feb 09 '16 at 10:07

0 Answers0