1
votes

I am using object oriented php to sign up and verify a user for my project website. I am using a bootstrap modal form to get all the needed information. All of my error handling is done in a Signup user class. When an issue happens with a user signing up, for example a user doesn't fill in a field I have it set up so that an error handler sends a message over the url using the header() function. The problem is that I don't know how to use the header() function to open the modal form so I can actually write the error message in the modal form so the user knows why the form suddenly closed. An example of one of the error handlers i use.

if ($this->emptyInput() == false) {
            $_SESSION["empty_input"] = "set";
            header("location:../index.php?error=empty_input");
            exit();
        }

The whole point of my question is to find a way to write out an error message in the modal form using this type of error handling. I am aware that this is not perfect or the best way to do it but I already built the majority of the signup like this.

A little bit more clarification. What I want to do when an error is caught is display the error message INSIDE the modal form. If I use the header() function it closes the modal form and opens the index page which i dont't want. What do I need to write inside the header() function to send the error message through the URL and open the modal form.

index.php would check $_GET['error'] and output the appropriate HTML/JS to display a modal…?!deceze
When you write header('location: foo'); all that happens is that the browser is told "please go to the URL foo", just like if the user had clicked a link with that URL. What you do when that URL is requested is entirely up to you, the reason it was requested isn't even detectable. So none of the code shown is relevant to your actual problem, which is "depending on the URL, I want different content to show".IMSoP
Note also that modals are generally used for the result of a JavaScript action, so that the whole page doesn't need to reload; but by the time your PHP runs here, you've already committed to loading a new page anyway. If you want it to check in the background and show the modal without reloading, you'll need to read up on "AJAX".IMSoP