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
parameter passing issue on function
Well I thought I had created a pretty slick web page, using ?page and $_GET to load pages which wher
Why do I get this error?
Error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or
Data storage spaces in varchar2
Trying to understand what's happening.
I am selecting a value from a table that is defined as c
Need help Updating SQL Server Express DB from c# :(
Please can anyone help with:-
1 How to sructure the strSelect statement.
2 How to instruct
How to make a input/output field with multiple lines
Hello.
I put a input/output field on the screen but I could not change height of it. I need to
php mail form text wont appear / javascript included
Guys/gals...
I am running into a problem whereby I have a great piece of javascript code that
try catch error
I have been trying try catch but, I can't get it to work. The code opens a non existing file called
Creating a custom API
I'm creating a site, and I need to create a basic API. Unfortunately I have no idea where to start.
RFQ Configuration - can you make PLANT field an optional field in ME42
Is there a way to make the plant field on an RFQ optional in change mode (ME42)?
SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built