There is a function in which data from the post request is filtered. How to transfer to this function the post itself array and correctly call the function?

function postData(){ $text = filterData($_POST['text'], 'string'); $link = filterData($_POST['link'], 'link'); $date = filterData($_POST['date'], 'date'); } 
  • filterData ($ _ POST); I understand that the filterData function is somewhere you have written, without its code it is impossible to figure out how to transfer the post itself to this function and correctly call it. - Opalosolo
  • And what's the problem just and pass to the function? function postData ($ _ POST ['text'], $ _POST ['link'], $ _POST ['date']) {# code} or I did not understand your question ... - --A
  • @ ua6xh, well, that's understandable. How to call? This is not how it works: $data = postData($_POST); - xenon
  • @ - A, it looks too cumbersome, I would like to immediately have an array, without listing it - xenon
  • @xenon why pass it if it is a super-global array? Unclear. I recommend using the filter_input function. In general, look towards the route . - And

2 answers 2

Call this function in the file to which you make a POST request.

 <form action='/controllers/forms.php'> 

In this example, in the forms.php file. If the action is empty or missing, then it sends a request to the same file on which the form itself is drawn. The $ _POST array is superglobal, so you don’t need to pass it as an argument, you can simply use it inside a function and score on your namespaces.

    File

     name="check['id файла']" 

    Handler

     $array = $_POST['check']; func($array); 

    Function

     function func($array){ for($array as $key){ echo $array[$key];}} 
    • Your answer does not contain a solution. - Klimenkomud