Trisha
Trisha

Reputation: 539

Why wont <button type="submit"> work?

I have a standard HTML form, and the button is not working. I know it is directing to the correct page, and as far as I can see everything looks perfect. It lets me click the button, but then nothing happens, it doesn't direct me to the send.php page or anything.

    <form method="post" action="http://www.URL.net/send.php">
    <p>
        <label for="name">Name <span class="required">*</span></label>
        <input type="text" name="name" id="name">
    </p>
    <p>
        <label for="email">Email <span class="required">*</span></label>
        <input type="text" name="email" id="email">
    </p>
    <p>
        <label for="subject">Subject</label>
        <input type="text" name="subject" id="subject">
    </p>
    <p>
        <label for="subject">Message <span class="required">*</span></label>
        <textarea name="message" id="message" cols="45" rows="10"></textarea>
    </p>
    <div class="fBtn">
        <button type="submit" name="submit" id="submit" class="regButton"><i class="icon-paper-plane"></i>Send Message</button>
    </div>
    </form>

Also, I have tried using <input type="submit" name="submit" id="submit" class="regButton" value="Send Message" /> as well, but it also isn't working for some odd reason.

Tested in Chrome and IE11.

EDIT Here is the JS for form vaildation:

$('#submit').click(function(){ 

$('input#name').removeClass("errorForm");
$('textarea#message').removeClass("errorForm");
$('input#email').removeClass("errorForm");

var error = false; 
var name = $('input#name').val(); 
if(name == "" || name == " ") { 
    error = true; 
    $('input#name').addClass("errorForm");
}


    var msg = $('textarea#message').val(); 
    if(msg == "" || msg == " ") {
        error = true;
        $('textarea#message').addClass("errorForm");

    }

var email_compare = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i; 
var email = $('input#email').val(); 
if (email == "" || email == " ") { 
    $('input#email').addClass("errorForm");
    error = true;
}else if (!email_compare.test(email)) { 
    $('input#email').addClass("errorForm");
    error = true;
}

if(error == true) {
    return false;
}

var data_string = $('.contactForm form').serialize(); 


$.ajax({
    type: "POST",
    url: $('.contactForm form').attr('action'),
    data: data_string,

    success: function(message) {
            if(message == 'SENDING'){
                $('#success').fadeIn('slow');
            }
            else{
                $('#error').fadeIn('slow');
            }
                }



});

return false; 
});

Upvotes: 0

Views: 6625

Answers (1)

Ry-
Ry-

Reputation: 224859

You appear to have some JavaScript that automatically submits every form using AJAX. Since you’re on the domain trishajohnson.net, the same-origin policy prevents JavaScript from opening requests to a (slightly) different domain – www.trishajohnson.net.

There’s an easy fix, though – just use the path part. It’s cleaner anyway.

<form method="POST" action="/tj/send.php">

Upvotes: 1

Related Questions