RomMer
RomMer

Reputation: 1089

Symfony crawler selectButton method can't get form

here is my html

<form  name="station" method="post" action="/stations/new" role="form">
   <div class="form-group">
     <label class="control-label required" for="station_name">Name</label>
     <input type="text" id="station_name" name="station[name]" required="required" maxlength="255" class="form-control" >
   </div>
   <div class="form-group">
      <div class="checkbox">
        <label for="station_active">
        <input type="checkbox" id="station_active" name="station[active]" value="1" />Active</label>
      </div>
   </div>
   <div class="form-group">
     <button type="submit" id="station_submit" name="station[submit]" class="btn btn-primary">Ajouter</button>
   </div>
   <input type="hidden" id="station__token" name="station[_token]" class="form-control" value="aze123aze" >
</form>

i want to get my form using the crawler. I tried the selectButton method like this

$form = $crawler->selectButton('station[submit]')->form(array());

but i get the error : InvalidArgumentException: The current node list is empty.

what is the problem ?

Upvotes: 3

Views: 2256

Answers (2)

slavchoo
slavchoo

Reputation: 81

Unfortunately I have no enough rating to just write a comment instead of put it in the answer.

So, could you please show how are you getting $crawler? Problem might be:

  • $crawler not point to DOM which contains this form

  • this form appears on page after some java script actions(Ajax for example), but not sure that this is your case.

Upvotes: 1

Matteo
Matteo

Reputation: 39470

The selectButton method accept the value The button text. So Try with:

$form = $crawler->selectButton('Ajouter')->form(array());

Hope this help

Upvotes: 0

Related Questions