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
Formatting echo from database
So I have a database that stores First and last names, then echos them back to a website, as of now
Re-Order by ID Number
I have a cms set up for inputting an image, thumb, title, pdf, and eps. When input the database ass
quick basic question, hopefully not dumb
I don't know how to search for this, so forgive me if it's been covered...
I often see an exa
socket makes browser hang...
I have a socket server, and I am having a problem at the moment...
A browser sends a http hea
Memory Allocation
Hi folks,
see this ex:
int v=5;
v=v+10;
then what will do the compiler before th
Procedural to OOP
John Kleijn said that to avoid writing "crappy code", we should learn OOP and common OO pr
Preg_match with an array
is there an away to use preg_match with an array?
i want to check a string with an array to s
This is driving me nuts!
This insert query looks to be alright, however I get this error:
QuoteYou have an error in yo
dinamic "textboxes"?
Ey all, my first post here, i hope its not a hard one
I display mysql results in a table
Send current URL in URL with a $_GET variable problem.
Hello community,
I have created a function that gets the current variable of a page, example: