codeboy89 Posted November 11, 2009 Share Posted November 11, 2009 Currently the script below works if the user does not type a name/message, but if i create a whitespace with the spacebar, it will submit. How would I fix this? message page: <?php // Get the file $file = implode('', file ("post.xml")); print " <form action=post.php method=post> <input type=hidden name=post value=yes> <p> Your Name<br> <input type=text name=name size=30> </p> <p> Message<br> <textarea name=message rows=5 cols=50></textarea> </p> <p> <input type=submit value=\"Post\"> <input type=reset value=Reset> </p> </form>"; ?> action page: <?php $name=$_POST['name']; $message=$_POST['message']; // Name and Message required if (( $name == "") || ( $message == "")) { print "<p align=center>Please go back to complete all fields!<p>"; } else { //Get the file $file_name = "post.xml"; $file_pointer = fopen($file_name, "r+"); $lock = flock($file_pointer, LOCK_EX); $file_read = fread($file_pointer, filesize($file_name)); //$name = strip_tags($name, ''); //$message = strip_tags($message, ''); $date = date ("j M Y"); $post = "\n\n<ponmurt>\n<p><span class=name>$name</span><span class=date> $date</span><br>$message</p>\n</ponmurt>"; //Paste the updated info into the file $post = stripslashes($post); fwrite($file_pointer, "$post"); fclose($file_pointer); print "<head><meta http-equiv=refresh content=0;URL=index.php></head>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181056-do-not-allow-posting-of-whitespace/ Share on other sites More sharing options...
mikesta707 Posted November 11, 2009 Share Posted November 11, 2009 you can trim the string. and then you could use empty to test it $string = " "; $string = trim($string); echo empty($string); output 1 btw 1 is true Quote Link to comment https://forums.phpfreaks.com/topic/181056-do-not-allow-posting-of-whitespace/#findComment-955318 Share on other sites More sharing options...
codeboy89 Posted November 11, 2009 Author Share Posted November 11, 2009 im new to PHP and lost Quote Link to comment https://forums.phpfreaks.com/topic/181056-do-not-allow-posting-of-whitespace/#findComment-955336 Share on other sites More sharing options...
Gayner Posted November 11, 2009 Share Posted November 11, 2009 im new to PHP and lost Not really php, just copy paste that code, lol Quote Link to comment https://forums.phpfreaks.com/topic/181056-do-not-allow-posting-of-whitespace/#findComment-955338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.