0

first off thank you in advance. I am writing a sign up page in PHP and using Jquery Validate to check the form. It is returning errors when the form is filled out incorrectly, but when it is correctly filled out it is just refreshed and not completing the actions I have delegated in the isset $_POST function. Here is what I am dealing with:

PHP If form is not empty

    //Escape high risk symbols

    $pw= mysqli_real_escape_string($con, $_POST['pass']);
    $username= mysqli_real_escape_string($con, $_POST['pass']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $sex = mysqli_real_escape_string($con, $_POST['sex']);
    $signedUp = date("Y-m-d H:i:s");
    $hash = password_hash($pw, PASSWORD_DEFAULT);

    echo 'Email: '.$email;
    echo 'Username: '.$username;
    echo 'Sex: '.$sex;
    echo 'Signed Up: '.$signedUp;
}
?>

Here is the Form

    <form method="post" class="form-signin" id="signup" name="signup">
                ...   
    </form>

Here is my validation javascript, it seems that it is not posting

<script src="js/formValidate.js"></script>
<script>
     // When the document is ready
     $(document).ready(function () {
         //validation rules
         $("#signup").validate({
             onkeyup: false,
             onfocusout: false,
             errorElement: "div",
             errorPlacement: function(error, element) {
                 error.appendTo("div#errors");
         },
         rules: {
             email: {
                 required : true,
                 email: true
                 //equalTo: "#example3-field2"
             },
             username: {
                 required: true,
                 minlength: 5
             },
             pass: {
                 required : true,
                 minlength: 5
             },
             cPass: {
                 required : true,
                 equalTo : "#pass"
             },
             sex: {
                 required : true
             },
         },
         messages: {
             email: {
                 required: "You must enter an email address",
                 email: "Enter a valid email address"
                 //equalTo: "Field 1 must be equal to Field 2"
             }, 
             username: {
                 required: "You must choose a username",
                 minlength: "Username must be a minimum of 5 characters"
             }, 
             pass: {
                 required : "You are required to enter a password!",
                 minlength : "Password must be at least 5 characters!"                                          
             },
             cPass : {
                 required : "You are required confirm your password!",
                 equalTo : "Passwords do not match"
             },
             sex : {
                 required : "You are required to choose a sex"
             },
         }, 
        submitHandler: function(form) {
            form.submit();
        }
    });             
});
</script>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • There's a lot there, can you try to narrow it down a bit to identify where the problem is? What are the errors you see? – msturdy May 08 '14 at 17:11
  • There are no errors showing at all. The form validate function is working. On submission of incorrect information it shows the error messages but when everything is filled out correctly it is just refreshing and not echoing the strings. –  May 08 '14 at 17:36
  • Your form really should have an action attribute to tell it where to submit to, otherwise the behaviour is up to the browser and includes doing nothing. – scragar May 08 '14 at 17:44
  • No it is in the same php page. No outside references needed. I figured it out, i was using isset, all I had to do was change it to if post isn't empty. Thank you guys for your help –  May 08 '14 at 17:49
  • I removed SOLVED: from the title. Accepting an answer marks it as being solved. @Vulgarity – Funk Forty Niner Sep 20 '17 at 13:24

2 Answers2

0

I think the problem is that you're trying to see if the FORM is there (signup), you need to validate one of the fields, for example:

if(isset($_POST['email'])){

Since you seem to be trying to validate the form and that index will never be present in $_POST.

Ozmah
  • 373
  • 1
  • 8
  • You're missing some text in the previous comment. I see you changed the question, now I don't understand what happened. – Ozmah May 08 '14 at 17:51
-2

You should use something like that to check if your request is a POST.

if($_SERVER['REQUEST_METHOD'] === 'POST') {
   // do your stuff.
}

related questions, Check whether a request is GET or POST

Community
  • 1
  • 1
JF Paris
  • 134
  • 4
  • The problem is not what kind of a request it is, the problem is whether the request is set and if it contain any data. – Jonast92 May 08 '14 at 17:56