Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP form error issue
    text
    copied!<p>There is probably a simple solution for this but i'm not very proficient in php! Basically I want to submit a form and the user be returned with a thank you overlay image without refresh. I've managed to get this to work BUT now the form validating isn't working properly...</p> <p>I need to make my overlay only appear after the form validating is successful, if it isn't successful I need to display the error instead of the thank you overlay...</p> <p>I know I could use ajax for this form but I don't want to rely on javascript!</p> <p>At the minute the validating is working, but the image is being overlayed on top of it...</p> <p>This is php code:</p> <pre><code>&lt;?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['formName'])) { $errorMessage .= "&lt;li&gt;You forgot to enter your name&lt;/li&gt;"; } if(empty($_POST['formTown'])) { $errorMessage .= "&lt;li&gt;You forgot to enter your town&lt;/li&gt;"; } $varName = $_POST['formName']; $varTown = $_POST['formTown']; $varAge = $_POST['formAge']; $varEmail = $_POST['formEmail']; $varOne = $_POST['hidden-one']; $varTwo = $_POST['hidden-two']; $varThree = $_POST['hidden-three']; $varFour = $_POST['hidden-four']; $varFive = $_POST['hidden-five']; if(empty($errorMessage)) { $fs = fopen("mydata.csv","a"); fwrite($fs,"\n" . $varName . ", " . $varTown . ", " . $varAge . ", " . $varEmail . ", " . $varOne . $varTwo . $varThree . $varFour . $varFive); fclose($fs); } } ?&gt; </code></pre> <p>This is my html (with the php code):</p> <pre><code>&lt;?php if (isset($_POST['formSubmit'])) { print "&lt;div class=\"thank-you\"&gt;&lt;a href='enter.php'&gt;&lt;img src='images/thankyou-overlay.png'/&gt;&lt;/a&gt;&lt;/div&gt;\n"; } ?&gt; &lt;div id="mainContainer"&gt; &lt;p&gt;Just complete your entry details below.&lt;/p&gt; &lt;?php if(!empty($errorMessage)) { echo("&lt;p&gt;There was an error with your form:&lt;/p&gt;\n"); echo("&lt;ul&gt;" . $errorMessage . "&lt;/ul&gt;\n"); } ?&gt; &lt;form action="&lt;? echo $_SERVER['PHP_SELF']; ?&gt;" method="post" target="_self"&gt; &lt;div class="inputContainer"&gt; &lt;label class="text" name="name"&gt;Full Name:&lt;/label&gt; &lt;input type="text" class="box" name="formName" value="&lt;?=$varName;?&gt;"&gt; &lt;/div&gt; ... more html inputs... &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload