0

What I'm doing: A sign up page, everything about it is fine, it checks all conditions and the infos goes to the database correctly.

What I want to add: After the infos are stored In the database, I'de like the user to be redirected to home page of the website with him logged in already.

What I did in solution: As I can't use a header() that contain $_POST[] values, I added a form that -if everything goes fine- stores the email and password in hidden textboxes, shows a message that everything went good, and have a submit button to redirect him to the home page of the website. that form is supposed to be invisible until the registration is completed, and here is the code I've made so far:

At the begining even before the <html> I have the php code

    $sign_up_success = false;
    /*php code checking if method is post, verify entries, return errors in cases,
    If everything is fine it saves the infos in he database, and sets $sign_up_success = true;*/

Then in the <head> I tried many javascript codes to make that form invisible, none of them seem to work, and here are some

    <script type="text/javascript">
        var state;
        <?php if($sign_up_success){echo 'state = visible';}
              else{echo 'state = none';}?>
        window.onload = function(){
        document.getElementById('login').style.display = state;
        }
    </script>

Same code above with echo "state = 'visible'";

    <script type="text/javascript">window.onload = function(){
    <?php if($sign_up_success){echo "document.getElementById(\'login\').style.display=\'block\';";}
    else{echo "document.getElementById(\'login\').style.display = \'none\';";}?>}</script>

Same code above using php variables instead of 'block' and 'none'

At body, I have this code:

    <div id="login"><form class="tble" action="testinginfos.php" method="post">
    Felicitation, vous êtes enregistré<br>n'oubliez pas d'ajouter une photo de profile<br><br>
    <input type="hidden" name="Email" value="<?php echo $usrmail;?>"><input type="hidden" name="Pass" value="<?php echo $usrpass;?>">
    <input type="submit" name="seco" value="Revenir au site">
    </form></div>

I tried with <p> instead of <div> but yeah it's the same lol I have a feeling that the solution is stupid, I've been working on this website all day long and I'm tired so if it is obvious maybe that's why I didn't see it, lets hope my feeling is wrong lol

I did google this and check other posts here and all of them uses jQuery or CSS and none uses php, that's why I've started a new post.

1 Answer 1

2

Wow I've found the answer just after I've finished writing my question, my feeling was right after all haha, so here I share it to help others if they get my same problem:

the correct code:

<script type="text/javascript">
    window.onload = function(){
<?php if($signupsuccess){echo "document.getElementById('login').style.display='block';";}
    else{echo "document.getElementById('login').style.display = 'none';";}?>}
</script>

what I was doing wrong:

  1. I didn't use window.onload = function(){} at the beginning.
  2. Then added the backslash \ to my code, so even after adding window.onload = function(){} nothing changed.
Sign up to request clarification or add additional context in comments.

2 Comments

I guess you need to display the login box again after it/s hidden? If not, just remove it from the HTML with you PHP condition, because hiding it in JS while you have access to server-side code is just convoluted and counter-productive.
@Capsule it's not a login box but yeah, after he finishes the registration, if there is no errors and the registration is done that box should show up with a button to redirect him.

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.