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

Problems with returning true or false in eval()'d code
Hi guys,

Would appreciate some help with a problem when running eval() on a function that sho

Install page
How do I make it so when a user submits information on the Install page, it'll right it into the cor

Include ("Absolute Path") of a file?
I'm not sure what I'm doing wrong. I am writing my php code in the same directory of the file that

duplicate record notification
In my database, after insertion of records, I want to know if the record inserted is duplicate or no

Checking if field is empty AND using !is_numeric
Hi lads,

Need to be able to display an error message (using isset?) that says "Cant lea

mail()
Hi all. I have a problem with emails. I am trying to set up a mail system where customers can subscr

noob question
i traying to do a php form with auto replay for both(me and the user who send me a mail),

a u

Results from Db outputted twice
Hey guys.. for come reason my data is outputted twise shown in the image below and i cant figure out

Display thumbnails as square while retaining aspect ratio
I am trying to figure out a way to make an image display as a square, for example 80x80 pixels, when

FILTER_CALLBACK -- Files?
Hi All,

I'm using the php filter functions to validate my form data. For custom filters, I'm

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