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
17
Other forums
Contact Form Not Working When I Add Validation Codes
So I built my first working PHP "Contact Us" like form. But, I have been trying to now mak
an interesting question
Greetings folks, got to ask an interesting question...
let say
i have created a function s
HELP with mysql_real_escape_string
I'm looking to remove apostrophes completely when someone enters lyrics but don't have a clue how to
Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?
This is what I've come up w
selection tool on raster image
Hi!
I have to implement in my app a selection tool which lets users to select region of any shape
How do I use a global footer..?
If my index.php has a bole bunch of if functions and exit's in them
How to add advertisment on top of videos
Hello,
I was told that i should find the answer for this problem in this forums.
I searched a
PHP template help
Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie an
how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass
Content-Disposition: attachment; filename=... not working as i thought it should
taken the following code from the php.net site the script is not working.
what is not happeni