Я пишу адрес, нажимаю ввод, появляется маркер с координатами.Я следую инструкциям, перехожу на следующую страницу, параметры URL передаются со значениями координат.Если я нажимаю кнопку назад, скрытые входы, в которых должны быть координаты, теряют необходимые значения, но адрес остается прежним.Если я снова последую инструкциям, на следующей странице координаты больше не передаются на URL, и в конце все ломается.Я не хочу терять значение координат до нажатия кнопки «Назад».Это возможно?(/ join - первая страница), (/ new - вторая страница)
***/join.html.twig***
<div class="form-group col-md-1 add-address-wrapper">
<div class="move-from-above"> </div>
<button type="button" class="btn btn-default btn-sm btn-set-location" aria-label="Set location"
data-toggle="modal"
data-target="#filterLocationModal"
data-address-field="#{{form.address.vars.id}}"
data-latitude-field="#{{form.latitude.vars.id}}"
data-longitude-field="#{{form.longitude.vars.id}}">
<img src="{{ asset('Resources/public/images/icons/map-point.png') }}" alt="">
</button>
</div>
<div class="form-group col-md-4 padding-left-none padding-right-none coordinates">
<label>
{% trans %}Destination address{% endtrans %}
</label>
{{form_widget(form.latitude)}}
{{form_widget(form.longitude)}}
{{form_widget(form.address, {'attr': {'readonly': 'readonly', 'class': 'form-control'}})}}
{{form_errors(form.address)}}
</div>
***/TripRequestController.php***
/**
* Creates a new tripRequest entity.
*
* @Route("/new", name="request_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
throw $this->createAccessDeniedException();
}
$tripRequest = $this->container->get('autotracker.trip_request')->getNewRequestStub($this->getUser());
if ($filterDate = $request->query->get('trip_date')) {
$tripRequest->setTripDate(new DateTime($filterDate, new DateTimeZone('UTC')));
}
if ($filterAddress = $request->query->get('dest_addr')) {
$tripRequest->getDestinationWaypoints()[0]->setAddress($filterAddress);
}
if ($filterLatitude = $request->query->get('dest_lat')) {
$tripRequest->getDestinationWaypoints()[0]->setLatitude($filterLatitude);
}
if ($filterLongitude = $request->query->get('dest_long')) {
$tripRequest->getDestinationWaypoints()[0]->setLongitude($filterLongitude);
}
$form = $this->createForm(
'Autotracker\RequestBundle\Form\TripRequestType',
$tripRequest,
['view_timezone' => $this->getUser()->getTimezone()]
);
$form->add('create', SubmitType::class, [
'label' => 'Create request',
])
->add('create_and_search', SubmitType::class, [
'label' => 'Create and initiate search',
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($tripRequest);
$em->flush();
if ($form->get('create_and_search')->isClicked()) {
return $this->redirectToRoute('request_edit', [
'id' => $tripRequest->getId(),
'_fragment' => 'driversearch',
]);
} else {
return $this->redirectToRoute('request_index');
}
}
$mapService = $this->container->get('autotracker.service.geo');
return $this->render('AutotrackerRequestBundle:TripRequest:new.html.twig', array(
'tripRequest' => $tripRequest,
'form' => $form->createView(),
'tz' => $this->getUser()->getDateTimeZone(),
'map' => $mapService->getGoogleMap($tripRequest->getClientAgency()),
'geocoderUrl' => $mapService->getGoogleGeocoderUrl(),
));
}
/**
* Join existing trip page.
*
* @Route("/join", name="request_join")
* @Method({"GET", "POST"})
*/
public function joinAction(Request $request)
{
$user = $this->getUser();
$tz = $user->getDateTimeZone();
$agency = $user->getAgency();
$em = $this->getDoctrine()->getManager();
$formBuilder = $this->createFormBuilder();
$formBuilder
->add('address', TextType::class, [
'constraints' => [
new NotBlank(),
]
])
->add('latitude', HiddenType::class)
->add('longitude', HiddenType::class)
->add('address_autocomplete', PlaceAutocompleteType::class, [
'mapped' => false,
'api' => false,
'variable' => 'autocomplete_address_popup',
'components' => [AutocompleteComponentType::COUNTRY => 'md'],
'types' => [AutocompleteType::GEOCODE],
])
->add('favorites', EntityType::class, [
'mapped' => false,
'required' => false,
'placeholder' => 'Choose address',
'class' => 'AutotrackerUserBundle:FavoriteAddress',
'choices' => $agency->getFavoriteAddresses(),
'choice_label' => 'address',
])
->add('date', DateType::class, [
'label' => 'Date',
'widget' => 'single_text',
'input' => 'datetime',
'html5' => false,
'format' => 'dd.MM.yyyy',
])
->add('filter', SubmitType::class, [
'label' => 'Show requests',
])
->add('create', SubmitType::class, [
'label' => 'Create new request',
]);
$form = $formBuilder->getForm();
$form->handleRequest($request);
$tripList = [];
if ($form->isSubmitted() && $form->isValid()) {
$filterDate = $form->get('date')->getData()->setTime(0, 0);
$filterAddress = $form->get('address')->getData();
$filterLatitude = $form->get('latitude')->getData();
$filterLongitude = $form->get('longitude')->getData();
if ($form->get('filter')->isClicked()) {
$tripList = $em->getRepository('AutotrackerRequestBundle:TripRequest')
->findJoinable(
$filterDate,
$filterAddress
);
} elseif ($form->get('create')->isClicked()) {
return $this->redirectToRoute('request_new', [
'trip_date' => $filterDate->format('Y-m-d'),
'dest_addr' => $filterAddress,
'dest_lat' => $filterLatitude,
'dest_long' => $filterLongitude,
]);
}
}
$mapService = $this->container->get('autotracker.service.geo');
return $this->render('triprequest/join.html.twig', [
'form' => $form->createView(),
'tz' => $tz,
'tripList' => $tripList,
'map' => $mapService->getGoogleMap($user->getAgency()),
'geocoderUrl' => $mapService->getGoogleGeocoderUrl(),
]);
}
Снимки экрана: https://prnt.sc/m2hvly
Координаты в скрытом вводе после нажатия «Выбрать адрес» - https://pp.userapi.com/c847219/v847219764/16748d/Dco4PV1g8h8.jpg
Атрибутыв URL на странице "/ new" - https://pp.userapi.com/c848520/v848520764/f11ff/u_4eCRexeDo.jpg
Ввод значений после нажатия кнопки "Назад" - https://pp.userapi.com/c849020/v849020764/f587b/x7f4Pixpd10.jpg