-5

Possible Duplicate:
How to prevent submitting the HTML form’s input field value if it empty

<?php

include '../core/init.php';
if(isset($_POST['nt']) && isset($_POST['ntb'])){
mysql_query("INSERT INTO `post` (`myid`, `text`) VALUES ('".$_SESSION['id']."', '".mysql_real_escape_string($_POST['nt'])."')");
}
?>

<iframe style="display:none" name="submissiontarget" id="submissiontarget"></iframe>
<form method="post" target="submissiontarget" action = "../ajax/post.php" name="form">
<input type="textbox" name="nt" class="postwall" id="nt"  placeholder="Post on your wall" rows="7" wrap="physical" cols="40" onfocus="if(this.value=='Post On Your Wall')this.value='';" onblur="if(this.value=='')this.value='Post On Your Wall';" />
<input type="submit" style="display:none;" name='ntb' id='ntb'  class="Buttonchat"     value="Post" />
</form>

I want to be able to do it so if the textbox is blank it says, 'Their was an error posting on your wall, please try again'.

Community
  • 1
  • 1
Bob
  • 11
  • 1
  • 7
  • `if ($_POST['nt'] == "") { echo 'error'; }` – sachleen Dec 01 '12 at 20:30
  • possible duplicate of [How to prevent submitting the HTML form's input field value if it empty](http://stackoverflow.com/questions/8029532/how-to-prevent-submitting-the-html-forms-input-field-value-if-it-empty) (…or any similar question here on SO; e.g. http://stackoverflow.com/questions/10516122/how-prevent-submit-if-input-are-empty-with-javascript) – feeela Dec 01 '12 at 20:33
  • not hard to research basic form validation in a simple web search. At least show a little effort before posting a question here – charlietfl Dec 01 '12 at 20:45

1 Answers1

0
if(isset($_POST['nt']) && isset($_POST['ntb'])) {
    …
} else {
    echo "There was an error posting on your wall, please try again.";
}

The catching of empty input submits on clientside, as demonstrated in the duplicate, might be an additional feature, but you won't get around doing it serverside.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375