Created a function to check post content

This commit is contained in:
Pierre
2018-01-14 19:29:45 +01:00
parent 29b989952d
commit cd4c9114dd
2 changed files with 39 additions and 7 deletions

View File

@ -346,4 +346,26 @@ function check_youtube_id(string $id) : bool {
//The video is considered as valid
return TRUE;
}
/**
* Get some content (for post actually) from a $_POST request
* and check its validity
*
* @param string $name The name of the $_POST field
* @return string The content of the post
*/
function getPostContent($name){
if(!isset($_POST[$name]))
Rest_fatal_error(400, "Please specify some content in '"+$name+"' !");
$content = $_POST[$name];
//Check the security of the content
if(!checkHTMLstring($content))
Rest_fatal_error(400, "Your request has been rejected because it has been considered as unsecure !");
//Return new content
return $content;
}