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
PHP If Else statement for breadcrumb
Hi
I am trying to use a PHP if else statement to display a breadcrumb link on wordpress
I need help on this PHP code
Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my
PHP / MySQL Associative Multidimensional Array:
Hello.
I have data in a MySQL Table that adheres to the below: (note, no index, could add if
PHP Cannot redeclare class
I have 6 files, and two of them do not seem to want to play well. I keep getting a "Cannot rede
php + mysql count consecutive data
I have a database of values and I want to work out how to display them if the values match a consecu
Material Issuing for receiving batch
Dear All experts in MM/ PP,
Material issuing from main stores to factory is currently usi
PHP - HTML
Could anyone give me some GOOD sample links for php - html email tutorial.
Thanks!
How can I get my program to read a larger array ??
Hi:
I have this program that reads from an array to do calculations. The array are just t
image upload script not working with png
The basic process of this php code is to take the submitted file, convert it to a small JPG thumbnai
Will an XHTML DOCTYPE interfere with my PHP if I'm not experienced enough?
I've read this article here: http://friendlybit.com/html/why-xhtml-is-a-bad-idea/
In a nutshe