2

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

1 Answer 1

2

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 !

Sign up to request clarification or add additional context in comments.

1 Comment

seems to work ! i will accept the answer in few minutes i can't atm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.