Silently classify submissions as spam using PHP only? #396
Replies: 1 comment 7 replies
|
Thank you very much for your question. This is possible, yes. Since you only want to know whether the data is valid, you only need two API requests. To see the submission in mosparo, you also need to do the verification part:
Here is a small script that would do the first two parts: <?php
require_once(__DIR__ . '/vendor/autoload.php');
use GuzzleHttp\Client;
$client = new Client(array());
$res = $client->post('https://YOUR_MOSPARO_HOST/api/v1/frontend/request-submit-token', [
'form_params' => [
'pageTitle' => 'Example form',
'pageUrl' => 'https://example.com/',
'publicKey' => 'YOUR_PROJECTS_PUBLIC_KEY'
]
]);
$data = json_decode((string) $res->getBody());
$res = $client->post('https://YOUR_MOSPARO_HOST/api/v1/frontend/check-form-data', [
'form_params' => [
'formData' => '{"fields":[{"name":"first-name","value":"John","fieldPath":"input[text].first-name"},{"name":"last-name","value":"Doe","fieldPath":"input[text].last-name"},{"name":"email-address","value":"john.doe@example.com","fieldPath":"input[email].email-address"},{"name":"website","value":"","fieldPath":"input[url].website"},{"name":"message","value":"This is an example message","fieldPath":"textarea.message"}],"ignoredFields":[]}',
'submitToken' => $data->submitToken,
'publicKey' => 'YOUR_PROJECTS_PUBLIC_KEY',
]
]);(I'm using this script to generate a high number of submissions in test scenarios) The The In the response to the second request, you'll find the validation token. With the validation token, you can make the verification request using the normal mosparo API client. But as I wrote above, it's not directly necessary to do the verification step in your case (since the user cannot manipulate anything after the form data validation by mosparo). But if you don't do the third step, you'll not see the submission in mosparo. I hope that helps you. Otherwise, please let me know if I can help you in any way. Kind regards, |
Uh oh!
There was an error while loading. Please reload this page.
Would it be possible to essentially use Mosparo as an API service for checking if a form submission is "spam" without relying on the front-end JavaScript?
Here's the request flow that I'm hoping to achieve:
Form submitted to my PHP contact form -> PHP contact form scripts submits form fields to Mosparo -> Mosparo returns valid true/false -> PHP contact form script silently marks submission as spam (if valid is false) but tells the visitor the form submission was successful.
This stops bots from learning that their submission is spam which prevents them from adapting and overcoming the spam protection.
I'm aware that there is an invisible mode, however it still tells the user if their submission is spam.
All reactions