Manage variables with PHP session

Asked

Viewed 264 times

4

I need to take the value of an input text to store it and use it on another page that opens automatically (popup) when the Send button of the form is pressed.

He can do this, but what’s happening is that when I press the button the first time it doesn’t pick up, when I press to send the form a second time it sends the value that was in the first time and so on... ideas?

  • try to put action="NomeDoPopUp" in your form.

  • keeps giving the same problem and in addition has one more thing, page 1 is a form that makes an entry in the database and only after this entry is created an ID (autoincremental) that I will use in the popup... so the action of the first form can not be the popup... =/

  • I’ll try to explain the case. Page1: makes the main register automatically generating a code in the table of the bank Page2 (popup): brings a list of checkboxes with options and that will be linked to the code I mentioned above in another table of the bank Because of this I need the first form to be sent first and only then another page comes with the check. Popup is only an aesthetic matter, not to open a page only for this... if you have any other solution)

1 answer

1

Your code is wrong. You are setting the value of $_SESSION['nome'] with a $_POST that does not yet exist and the same situation is repeated when calling the popup.

Do so

<?php

    session_start('professor');

    $chamarPopup = false;

    //Verifica se existe um $_POST chamado nomeP, que é o name do seu input.
    if (isset($_POST['nomeP']) && !empty($_POST['nomeP'])) {
        $_SESSION['nome'] = $_POST['nomeP'];
        $chamarPopup = true;
    }

?>

<form method="post" name="formTest">
    <input type="text" name="nomeP" value="Nome Professor">
    <input type="submit" value="PopUp">
</form>

At the end of your page, after the tag </body> put this

<?php

    if ($chamarPopup === true) {
        echo "<script>window.onload = function(){";
        echo "varWindow = window.open ('cadastro_prof_disc.php', 'popup', 'width=1024, height=350, top=300, left=400%, scrollbars=no, resizable=yes,')";
        echo "};</script>";
    }

?>

No popup need change anything.

Just for the record: I don’t recommend using popup, because most modern browsers block all by default and, less experienced users don’t know how to do so that they are displayed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.