Jump to content

PHP error handling to limit characters in textarea.


codeboy89

Recommended Posts

Here is the code for my message page and below it the code that posts the message. Can anyone please show me how to add a character limit of 3000 to the message/textarea?

 

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<br>

<input type=text name=name size=30>

</p>

<p>

Message<br>

<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 = "\n\n<ponmurt>\n<p><span class=name>$name</span><span class=date> $date</span><br>$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>";

}

 

?>

Would this be the correct way to add it?

 

// Name and Message required

if (( $name == "") || ( $message == "")) {

print "<p align=center>Please go back to complete all fields!<p>";

}

if (strlen($message) > 3000) {

print "<p align=center>Too long!<p>";

}

else {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.