I want to display messages at top ids “MessageError” and “MessageOK” according to POST results. Example:
<p id="MessageError"></p>
<p id="MessageOK"></p>
<form name="Form" method="post" action="<?php $_SERVER[ 'PHP_SELF' ]; ?>" enctype="multipart/form-data" accept-charset="UTF-8" id="Form">
<input type="text" name="test" value="" /> <input type="submit" name="Submit" value="" />
</form>
<?php
if ( isset ( $POST[ 'Submit' ] ) ) {
if ( $_POST[ 'test' ] ) {
// Echo message at "MessageOK
}
else {
// "Echo message at "MessageError"
}
}
?>
Any help will be appreciated.
Thank you.
Move the code above your form to print the error message above your form. Also your paragraph tags can be created on the fly, to avoid waste:
If you are dead set on adding content to pre-created divs using PHP, can I suggest creating an input using PHP eg:
And then using JavaScript to append data: