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
how to remove in php string display
My code is
$message="We're looking at developing our website.";
$body= "
help with variable
I've got a problem, i want to echo some images depending on the $id, however for me to get that id i
Had a simple form script that suddenly stopped working
It was made about a year ago and had been working fine. Last time it was known to work for sure was
delete comma
HI,
How to delete "," at the end of the string.
Code: $match = 2009/02/03/a2corr
error checking breaking my code
Hi there, OK first of all, big apologies for what I assume is really fundamental errors in the struc
Running External Scripts
I am very new to PHP and am not even sure what I'm asking is possible. I have just installed mediaW
error reporting
hey everyone
I have a production server in which I want error reporting but only on some page
'210010106140040100' == '210010106140040101'
Debugging this simple line of a PHP script
Code: if($a == $b){ }
I've found that with val
Accept only alpha characters
I've got this bit of code ready for accepting a phrase:
Code: if (!eregi ("", $_POS
HTAccess auto log in?
Hi all.
Too busy driving celebs about lately so I hope someone here can help me out.
I