I have a form in 'index.php' in wich I will validate some text fields using 'submit.php', if everything is ok it should insert the fields into my database using 'submit.php'. Now, if 'submit.php' detects an error it should echo the errors I stored in an array under my form at 'index.php':
INDEX.php :
<form action="submit.php" method="POST">
<input type="text" name="email" />
<input type="text" name="url" />
<input type="submit" name="Submit" value="Continue"/>
</form>
<div class="errorsgohere"><?php //WHAT TO ADD HERE? ?></div>
SUBMIT.php :
if(isset($_POST['Submit'])) {
//I validate everything... etc..
if(!empty($errors)) {
echo "<div class='errors'>";
foreach($errors as $error) {
echo $error;
}
echo "</div>";
} else { SubmitDatabase(); //If there are no errors it will proceed }
}
How can I echo what I have in $error BUT in INDEX.php inside my and if possible without refreshing the whole page? Thanks in advance!