PHP - Thread Validation Add validation that checks: $title and $message both hav
ID: 3780726 • Letter: P
Question
PHP - Thread Validation
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:
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:
Add your code to newthread.php. Test your script by running:
Given:
newthread.php
Explanation / Answer
the following code validates the length of the required variables and display respective json text
$suc="status”: 432, “error”: “title field is too short"
$unsuc="status”: 200"
if((3<=$title=<32)&&(3<=$message<=52))
{
echo json_encode($suc)
}
else
{
echo json_encode($unsuc)
}
hope this would help you to get an initiation............all d best
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.