Do not allow posting of whitespace
Posted on
16th Feb 2014 07:03 pm by
admin
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
<input type=text name=name size=30>
</p>
<p>
Message
<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 = "nn<ponmurt>n<p><span class=name>$name</span><span class=date> $date</span>
$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>";
}
?>
No comments posted yet
Your Answer:
Login to answer
191
17
Other forums
iterating through an array and escape each value independently.
I have a set up where the variable being escaped is an array and it needs to be iterated and escaped
HELP with mysql_real_escape_string
I'm looking to remove apostrophes completely when someone enters lyrics but don't have a clue how to
Day of week
I am using PHP version 5.0.5
I have a varaible ($DATE (date format yyyy-mm-dd)) that is being inc
text box alphanumeric caracters only
hi all!
I have search on google on how to enter in a test box only caracters A-Z,a-z,0-9 usi
how to timeout $doc = new DOMDocument()->load($url)
I am currently using this $doc->load($url) to fetch an rss feed.
If a feed takes long than
Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a ga
media recovery
Hi,
i startup the database i got the error
SQL> startup
ORACLE instance started.
Syntax error
hi im having a little trobble with this script
-------------------------------------------------
Save User Inputs while javascript reloading!
hi..
i have written a PHP code in which i reload the page when user selects a value in dropdown..