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 Like 17 Dislike
Previous forums Next forums
Other forums

Auto fill in input value based on User_ID
Hello,

I'm looking form some input on the following problem.

User loads page ->

Posting Serialized Data Not Working
I am trying to send an object from one PHP file to another using POST. I serialize the object and th

Frustrated php Newbie
First off, I am pretty much a PHP nub. I can read and understand the language (most of the time) so

Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi

How do I know when getBounds Method is ready to be called.
I have an application that changes out stylesheets client side. Once I change stylesheet the browse

php/xmlrpc class issue
I am working on xml-rpc in php to start with.

I have a class that only has variables defined

How would I do "Users not logged in since *** delete them"
I know how I would set this up, and delete the user roughly.
I'll create a table called "Use

Merger of 6 sister companies under one flagship company after go live
Dear Experts,
I need one help regarding Merger of sister companies of same group. currently we

Looking for help on using joining mysql tables and php....
Does anyone have any good links to references on how to pull mysql data, through joining tables and

is this the proper use of mysql_real_escape_string() to prevent sql injections?
i was wondering is this the proper use of mysql_real_escape_string() to prevent sql injections? any

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