0

Ok, I'm making a login and registration panel with jquery and php. In short, if there are errors with the registration it sets a few form errors, redirects back to the registration page, the javascript detects there are errors with the use of a php variable and forces the slider to show itself.

The working code: Above the doc type $errors = $form->num_errors; and the whole $errors routine works fine.

My problem is that I also have a verification that the form was submitted successfully. It uses

if(isset($_SESSION['regsuccess'])){
    $success = 1;
} else {
    $success = 0;
}

to set the $success variable. The crazy thing here is that this doesn't work using the same routine as the $error variable. I know the $success conditional is working correctly as I have an it echoed out further down the page.

jQuery slide script:

$(document).ready(function() {

    var num_errors = "<?php $errors; ?>";
    var form_success = "<?php $success; ?>";

    // Expand Panel
    $("#open").click(function(){
        $("div#panel").slideDown("slow");
    });
    // Collapse Panel
    $("#close").click(function(){
        $("div#panel").slideUp("slow"); 
    });     

    // Switch buttons from "Log In | Register" to "Close Panel" on click
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });      

    //this part works
    if(errors>0){
        $("div#panel").slideDown();
        $("#toggle a").toggle();
    }

        //this part doesn't
    if(form_success>0){
        $("div#panel").slideDown();
        $("#toggle a").toggle();        
    }

});

The demo page is here http://demo.ivannovak.com/danlogin/index.php

Suggestions would be appreciated, thanks!

1 Answer 1

2

In your page, you have an errors variable defined, that's why that portion works:

<script type="text/javascript" language="javascript"> 
<!--
errors = 0; // -->
</script> 

Your javascript file isn't processed by php, it's served directly by the web server so your variables in what you listed above:

var num_errors = "<?php $errors; ?>";
var form_success = "<?php $success; ?>";

Those come out exactly that way to the client, they aren't replaced with their values. You need to move those 2 lines into your page where you have errors now, and remove them from quotes as well. Take them out of your js and use this in your page:

<script type="text/javascript" language="javascript"> 
  var num_errors = <?php $errors; ?>;
  var form_success = <?php $success; ?>;
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.