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>";
}

?>

191 Like 17 Dislike
Previous php-forum Next php-forum
Other php-forum

problem with refreshing
in my site, i have an index page, it has a main div. this main div's content is changing according t

Just wondering what you think about my site
I am new to phpfreaks i just seen this form and thought it would be cool to see what other thought a

regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q

MYSQL gen help
This is my Mysql gen. can anyone tell me why this echos

MID(networkset.networkid, 3, 3) AS &q

PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi

Using two $_POST Function / Switch () statements, second does not work.
Hi all. I’m new to php and am having a problem getting $_POST Function / switch () to work. I

Validating time
Hi Guys

what do you think of the following approach to validate a 24hour time:

http://

PHP XML extraction text
I would like to extract an xml text and have that text directly echo(print) out on my web page. Her

Strange HTML Tag?
I recently noticed some odd HTML appear in some of the websites I host. Not all of them are run on a

dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but i

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