Search the Community
Showing results for tags '$session-set()'.
-
Hi all, I want to process a form, and display an error message under certain conditions. I know there are other ways of doing this, but I kind of like the idea of using $session->set and $session->get to store and retrieve my error messages. This is the first time I have used $session->set(). Is this method ok? <?php $error = $session->get($errorMsg); echo $error; // Clear the session variable so it doesn't display again if the page is reloaded. $session->set($errorMsg, ""); // If the submit button is clicked, process the form. if($input->post->submit) { $test = $sanitizer->textarea($input->post->test); if($test==""){ $error = "Error: You left it blank!"; } elseif($test=="poop"){ $error = "Error: Poop is not allowed!"; } else { $error = ""; } $session->set($errorMsg, $error); $session->redirect('./'); // If the submit button hasn't been clicked, render the form. } else { echo "<form action='./' method='post'> <fieldset> <legend>Testing a form with validation...</legend> <div class='row'> <div class='large-12 columns'> <textarea name='test' rows='10'></textarea> </div> </div> <div class='row'> <div class='large-12 columns'> <button class='small' type='submit' name='submit' value='Send'>Test</button> </div> </div> </fieldset> </form> "; }