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
Validation
Hello
I know this is a really vag question.
I need to have a input field on a form th
PHP Upload issue
Hi guys,
I have stumble across an interesting issue with my script and is doing my head in.
check_changed_data - I can't get data from the called method event
I use check_changed_data to trigger my event method.
The method delivers er_changed_data.
registration form
first time posting. did some searches but didnt find exactly what i am looking for. dont flame cause
unserialize help, getting errors
hi all ,
I got a form with 6 fields (2 input and 4 select box), when the page loads one block is
Display search result
Hi!
I have a SQL database with information about albums and track (music).
This is wh
Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va
regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q
Text Not Displaying Correctly With PHP:GD
I recently moved servers and since then I have noticed that one line of text is showing weirdly.
Read from a text file after a specific word
Hi all.
I have a text file that looks like the one below.
I know how to open the text fi