RomMer
RomMer

Reputation: 1089

Access twig generated-form fields in PHP Symfony 2.8

I have a view generating a form using twig. I want to set the fields of my form in my php test code

here is the view

{{ form_start(trackImageForm, {'attr': {'id': 'add_image_form'}}) }}
<div class="modal-body">
  {{ form_rest(trackImageForm) }}
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
  <button type="submit" class="btn btn-primary" onclick="$(this).prop('disabled', true)">Télécharger</button>
</div>
{{ form_end(trackImageForm) }}

here is the html

<form name="track_image" method="post" action="/app_dev.php/tracks/4201/images" id="add_image_form" role="form">
  <div class="modal-body">
    <div class="form-group">
      <label class="control-label required" for="track_image_origin">URL</label>
      <input id="track_image_origin" name="track_image[origin]" required="required" class="form-control" type="url">
    </div>
      <input id="track_image__token" name="track_image[_token]" class="form-control" value="-oUtauxxNRWUATvw9t0R5rQftzbwTGKxZbTTnXVNp-o" type="hidden">
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
    <button type="submit" class="btn btn-primary" onclick="$(this).prop('disabled', true)">Télécharger</button>
  </div>
</form>

here is my php code

$form = $crawler->selectButton('Télécharger')->form(array('HERE IS MY PROBLEM' => 'http://www.test.com/image.jpg'));

i want to set the URL field to the value i want but i can't access it. can someone show me please ? thank you

Upvotes: 2

Views: 85

Answers (1)

Arne
Arne

Reputation: 381

You should probably use the full input name like ;

$form = $crawler->selectButton('Télécharger')->form([
   'track_image[origin]' => 'http://www.test.com/image.jpg'
]);

As the DOMCrawler is not aware of the Symfony Form component !

Upvotes: 2

Related Questions