0

I have a page where you fill in a form, I added try catch exceptions and this works fine after it is submitted. Now I would like the data that is filled in the form to be displayed on a other page. How do I get the exception to still work? Now the page is redirected without the exceptions being done.

code on the same page:

  <form action="#" method="post">
  <option value="Kies een hoogte">Kies een hoogte</option>
    <option value="13cm">13cm</option>
    <option value="17cm">17cm</option>
    <option value="21cm">21cm</option>
</select>
<span class="error"><?php echo $hoogteError ?></span>

The exception:

try {
        if ($hoogte == "Kies een hoogte") {
            throw new Exception(" Maak een keuze!");
        }
    } catch (Exception $e) {
        $hoogteError = $e->getMessage();
    }

What I would like is the exception to work when I use this:

 <form action="prijsopgave.php" method="post">

What should I do or use to make this work?

George
  • 25
  • 1
  • 7

1 Answers1

0

Add onsubmit event which returns true or false in the form, which validates in client-side.

<form action="prijsopgave.php" method="post" onsubmit="event.preventDefault(); validateMyForm();">

JavaScript code to stop form submission

The scion
  • 1,001
  • 9
  • 19