Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mastergalen's avatar

How to $this->type() in a hidden input

I want to write a test in Laravel 5.1 that submits a form, with one of the fields being a hidden input.

The HTML for the hidden input is:

<input name="description" type="hidden">

 $this->visit('form')
             ->type("Example description", "description")
             ->press('Submit')

However, when I try to run the test I get an InvalidArgumentException: Unreachable field "0".

Is there some method I'm missing in CrawlerTraits.php that would allow me to fill in a hidden input?

0 likes
5 replies
gregurco's avatar

DomCrawler (that are used there) can't process hidden inputs.

raomaster's avatar

i use :

<input type="hidden" id="id_oculto" name="id_oculto" value="">

then in test:

 $this->visit('form')
             ->type(2, "id_oculto")
             ->press('Submit')

and all is ok.

bobbybouwmann's avatar

@gregurco What about the hidden field _token? It can process that fine, so other fields should work as well

1 like
alariva's avatar

@bobbybouwmann good point.

I'm willing to alter the _token field to simulate an expired or tampered token for my tests. Any solutions/suggestions so far?

Please or to participate in this conversation.