I want to know if it is okay to validate the form from JS first to know that the data entered is correct, if not, do not send the request; that is to say, that it is only string, numbers, etc, already in PHP clean the variables and do what you have to do with them. Is it ok like this or does it have to be validated from PHP?
I am going to try to answer you with facts, although the question lends itself to opinions and there is still a newscast left for them to close it:
If you validate the data in the frontend , you avoid sending unnecessary requests to the backend. For example, if you have a form with a user email field and the user types it wrong and submits the form, the backend will receive that wrong email, validate it, return an error response, etc. Many steps, executed code and communications that could be avoided if you validate it through JavaScript, which is above all code that is executed by the user machine, thus offloading work to our backend.
Also, validating in the frontend has usability advantages, since you can immediately give feedback to the user that the field they are typing is not valid.
Regarding backend validation : you can't assume that if you already have frontend validations you won't need backend validations. A form can be forged that sends invalid data to your endpoint. Continuing with the previous example, if you have a JavaScript validation that checks if an email is correct and then you do not do that same validation in the backend, a person could create a form that sends an email without an at sign to the backend, your JavaScript validation does not it would come into play and your backend would gobble up that invalid email, which could then cause problems elsewhere in the application; for example if you tried to send an email to that address without an at sign.
It should also be noted that there are certain types of validations that must necessarily be done in the backend.