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:

Did you know?Explore Trending and Topic pages for more stories like this.
<?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 Like 17 Dislike
Previous forums Next forums
Other forums

need help about
i store the value of my select statement result to an array and stored it to a variable named $fname

Prevention Help
How can I use PHP or any other language (feel free to move this thread) to prevent users doing scree

Preventing SQL Injection
I have a question about SQL Injection, In some of our code we use this: view plaincopy to clipboa

Why does this file not return file names that start with numbers?
This file returns a list of filenames to help populate a drop down in my form. For some reason it ig

List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab

How to know if online site made with PHP
Hello,
I see some sites that does not display extensions at all , for example:

www.site.co

Header is not working in IE
Hi ! header function is not working in IE but it works in FF, Safari, Chrome. any help please. :

PHP doesn't send my mail
Hi all, I found this and used it to send mail. Simple contact form with some required fields. The va

Count on multidimensional array
Hi, i got an array as below:

Array
(
=> Array
(

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash