Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here are is my php code,
PHP
<?php
    $data= array();
    $from = $_POST['email'];
    $full_name = $_POST['fullname'];
    $number=$_POST['number'];
    $subject = "Contact Form submission";
    $messages = $full_name . " " . " sent you this message:" . "\n\n" . $_POST['message']. "\nPlease contact  ".  $full_name ." via email ". $from . " or call them at ". $number;

  
    $data['success'] = true;
    $data['message'] = 'Thank you. We will get back to you shortly!';

    // return all our data to an AJAX call
    echo json_encode($data);

    ?>

Python







and here is my javascript file

// magic.js
JavaScript
$(document).ready(function() {

    // process the form
    $('form').submit(function(event) {

        // get the form data
        // there are many ways to get this data using jQuery (you can use the class or id also)
        var formData = {
            'email'              : $('input[name=email]').val(),
            'fullname'             : $('input[name=fullname]').val(),
			'number'             : $('input[name=number]').val(),
            'message'    : $('input[name=message]').val()
			
        };

        // process the form
        $.ajax({
            type        : 'POST', // define the type of HTTP verb we want to use (POST for our form)
            url         : 'mail_processor.php', // the url where we want to POST
            data        : formData, // our data object
            dataType    : 'json', // what type of data do we expect back from the server
                        encode          : true
        })
            // using the done promise callback to handle successful ajax request
            .done(function(data) {

                // log data to the console so we can see
                console.log(data); 

                $('form').append('<div class="alert alert-success">' + data.message + '</div>');

            // usually after form submission, you'll want to redirect
            // window.location = '/thank-you'; // redirect a user to another page
            alert('success'); // for now we'll just alert the user

            });

        // stop the form from submitting the normal way and refreshing the page
        event.preventDefault();
		
	
    });

});



When I click submit, nothing happens. The button won't click and I can't seem to figure out whats wrong with it. Please help.
Posted

1 solution

remove event.preventDefault & try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900