Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Fields/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ public function filterPrecognitiveRules($rules)
{
$request = request();

if (! $request->headers->has('Precognition-Validate-Only')) {
if (! $request->headers->has('Precognition')) {
return $rules;
}

return Collection::make($rules)
->only(explode(',', $request->header('Precognition-Validate-Only')))
->only(explode(',', $request->header('Precognition')))
->all();
}
}
17 changes: 17 additions & 0 deletions tests/Tags/Form/FormCreateAlpineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Tags\Form;

use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Form;
use Statamic\Statamic;

class FormCreateAlpineTest extends FormTestCase
Expand Down Expand Up @@ -932,6 +933,22 @@ public function it_dynamically_renders_precognition_text_field_x_on_change()
$this->assertFieldRendersHtml(['<input id="[[form-handle]]-form-name-field" type="text" name="name" value="" x-model="form.name" @change="form.validate(\'name\')">'], $config, [], ['js' => 'alpine_precognition']);
}

#[Test]
public function it_wont_submit_form_when_precognition_validate_only_header_is_spoofed()
{
$this->assertEmpty(Form::find('contact')->submissions());

$this
->withHeaders([
'Precognition-Validate-Only' => 'foo',
])
->post('/!/forms/contact', [])
->assertSessionHasErrors(['email'], null, 'form.contact')
->assertLocation('/');

$this->assertEmpty(Form::find('contact')->submissions());
}

private function jsonEncode($data)
{
return Statamic::modify($data)->toJson()->entities();
Expand Down
Loading