0

I'm currently running a forum-like site where if a user leaves the post completely empty and hits the post button, an error is thrown. What I would like, is to replace that error (an empty string) with static content. So, for example, that automatically the words No comment get posted, instead of an error being thrown.

The relevant code currently is:

if ($stripped_whitespace == '') {
    error($config['error']['tooshort_body']);
}
Alexis Philip
  • 517
  • 2
  • 5
  • 23
Hovic
  • 1
  • Couldn't you just set a minimum length on the field - https://stackoverflow.com/questions/10281962/is-there-a-minlength-validation-attribute-in-html5 – Nigel Ren May 01 '20 at 09:32

1 Answers1

0

I think first we have to know which variable holds user content before sending to storage (database), let say.

 if($_POST['comment']){
    //true so send $comment to database;
    $comment = $_POST['comment'];  // you have to validate this <--- for sure :)
}else{
   //false, so instead of error
    $comment = 'No Comment';
}
Sayd Fuad
  • 313
  • 2
  • 14