razzek
razzek

Reputation: 609

Send values to controller from twig

I have integrated google maps in my views new.html.twig and I get the the latitude and the longtitude like this in table:

<input size="15" type="text" id="latbox" name="lat" value=""> 
<input size="15" type="text" id="lonbox" name="lon" value="">

I need to send these two values to a controller to insert them into my database. How can I send them to a controller?

Upvotes: 1

Views: 2420

Answers (2)

Gara
Gara

Reputation: 626

If it is POST request then

<form action="path/to/controller" method="POST">
<input size="15" type="text" id="latbox" name="lat" value=""> 
<input size="15" type="text" id="lonbox" name="lon" value="">
<input type="submit" value="submit" />

In Controller

$lat = $request->request->get('lat'); $lon = $request->request->get('lon');

Upvotes: 1

Sehael
Sehael

Reputation: 3736

Here is a minimal example

<form action="path/to/controller" method="GET">
    <input size="15" type="text" id="latbox" name="lat" value=""> 
    <input size="15" type="text" id="lonbox" name="lon" value="">
    <input type="submit" value="submit" />
</form>

and in your controller

$lat = $request->query->get('lat');
$lon = $request->query->get('lon');

There are several ways to actually submit the data, this is just a basic example

Upvotes: 3

Related Questions