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

RadioButtonList item spacing
I have a RadioButtonList and I can't put any spacing between the items. They are arranged verticall

This is driving me nuts!
This insert query looks to be alright, however I get this error:

QuoteYou have an error in yo

Multi Level Array Problem
hi all,

For example I have array like below:

$temp = array(array('north america', 'us'

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

True way to see if action was successful?
If this is a good way to see if action was successful to continue:

Code: function changeGa

Question about the upload of large files
Hi there,

I have a question about the upload of large files, like videos (files generally abo

How a counter of users ? such as ---> (231 Viewing)
I want to count how many users are actually viewing the page, How is that possible?
Thank you guy

array_combine() error
getting an "Warning: array_combine() [function.array-combine]: Both parameters should have an e

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

Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,

Its been a while, I know. Use to love coming here to answer peoples questions, but

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