I am trying to make a system that brings me the data from a form on a page and inserts a data already defined in variables.
The problem is that I have the one that I don't know how to bring the form data to autocomplete.
This is the script with the defined data:
<?php
$postData = array(
'name' => 'Sebastian',
'post' => 'Esto es un texto de prueba'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://scribbble.000webhostapp.com");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
print_r($data);
curl_close($ch);
?>
I updated the data because it was not up to date. But I can't get the data to enter the form.
I answer so that you understand how it works, but you will have to adapt it for your specific cases.
You are wanting to submit the form found at https://scribbble.000webhostapp.com . The first thing you have to do is check to which URL the form is sent and what parameters are sent. Once you get that, you have to simulate the POST. In some cases, that alone may not be enough, because they may be checking something else from the backend.
I entered that URL, made a publication and from the "red/network" tab of the browser I reviewed the data:
- URL to which it is sent: https://scribbble.000webhostapp.com/ (it is the one
action
of the form, in this case it is sent to the same URL where the form is located). - Parameters: - name: Entered name - post: Message text - add: empty parameterObtained the data, I replicated it from cURL:
If you run that script you will see that the message is published.
In this case, what it returns is the content of the site with your new message. But it is not important what it returns, what matters is that the message is published.
You will have to test this process with each of the sites and you will have to adjust the fields accordingly.
at the top you are making a post request, that what it does is send the form without human validation, to what I understand you need to do human validation, so, you need to make a get request first to the first page, if you don't have any api you can parse the code looking for a pattern, for example classes or even with the same input name=" with the preg_match_all function, now, correct me if the steps are correct, 1. Obtain information from a contact form already with predefined data, 2. print that data in another form for someone to edit and/or click submit 3. submit the form.