Question: PHP - Validation & Thread Add validation that checks: $title and $message both have a minimum length of 3. title has a maximum length of

PHP - Validation & Thread

Add validation that checks:

$title and $message both have a minimum length of 3.

title has a maximum length of 32 characters.

$message has a maximum length of 52 characters.

If any of the three validation rules fail, print a status of 432 and an error message of what is wrong with the user input. The JSON response should look like:

{status: 432, error: title field is too short} 

If the user submitted a successful post, save the record using the provided Thread class. Set the timeposted set to when the item was submitted. Make the thread visible as soon as its submitted. Print a status code of 200. The JSON response should look like:

{status: 200} 

Add your code to newthread.php. Test your script by running:

php newthread.php "My Title Here" "My Message here" 

ALSO convert all urls in the $message to HTML links and store the new result as message_html using the provided Thread class.

HINT: You'll need to modify the provided Thread class.

-------------------------------

newthread.php

 

------------------------

Thread.php

db = new DatabaseFile(); } /** * @param string $title * @param string $message * @param bool $isVisible * @param int $timePosted */ public function newThread($title, $message, $isVisible, $timePosted) { $this->db->insert('thread', [ 'threadid' => $this->db->primaryKey(), 'title' => $title, 'message' => $message, 'visible' => intval($isVisible), 'timeposted' => $timePosted, ]); } /** * @param int $numThreads * @param bool $includeHidden * * @return array */ public function getRecentThreads($numThreads, $includeHidden) { $columns = [ 'threadid', 'title', 'message', 'timeposted', ]; $conditions = ($includeHidden) ? [] : ['visible' => 1]; return $this->db->select('thread', $columns, $conditions, 'timeposted', false, $numThreads); } } 

-------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!