Reputation: 155
i'm new to programing, i have a basic symfony form that works perfectly, what i'd like to do is while i'm typing the text in some fields, i want it to be displayed at the same time in a div block placed on the top of the form. is it possible?
i've tried something like
//...
$entity = new Invite();
$form = $this->createForm(new InviteType(), $entity);
$form->handleRequest($request);
$adress = $form['adress']->getData();
//....
return array(
'entity' => $entity,
'form' => $form->createView(),
'adresse' => $adresse,
);
and in the twig file
<div>
{% if adresse is defined %}
{{adresse}}
{% endif %}
</div>
thanks for your time and answers!
Upvotes: 0
Views: 105
Reputation: 2297
What you have there will work only upon submitting the form and have it processed by PHP.
What you need now is Javascript on the browser side to do some work copying from the form field to the div.
So, add an ID to the div like so:
<div id="adress-live">
then the following should work:
<script>
var field = document.getElementById('adress');
var target = document.getElementById('adress-live');
field.onKeyUp = function() {
target.innerHTML = field.value;
};
</script>
Upvotes: 2