View difference between Paste ID: TacL7g7v and Kj17qugb
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
class Foo
4
{
5
6
    public function detailsAction(Request $request, $quoteId)
7
    {
8
        $service = $this->get('surely_platform_api.platform_api_service');
9
        $form = $this->createForm(new PersonalDetailsType());
10
11-
        $form->handleRequest($request);
11+
        if ($form->handleRequest($request) && $form->isValid()) {
12
            $formData = $form->getData();
13-
        if ($form->isValid()) {
13+
14
            $emailAddress = $formData['email'];
15
            $personalId = $formData['person_id'];
16
            $phoneNumber = $formData['mobile'];
17
18
            $apiResult = $service->createPolicyForQuote($quoteId, $emailAddress, $personalId, $phoneNumber);
19
20
            if (false == $apiResult->hasErrors) {
21
                return $this->redirect($this->generateUrl('dental_agree', array(
22
                    'policyId' => $apiResult->result,
23-
                $policyId = $apiResult->result;
23+
                )));
24
            }
25-
                return $this->redirect($this->generateUrl('dental_agree', array('policyId' => $policyId)));
25+
26
            // Do something
27
            foreach ($apiResult->errors as $error) {
28
                $form->addError(new FormError($error->Message));
29
            }
30
        }
31
32
        return array(
33
            'form' => $form->createView(),
34-
        $apiResult = $service->getQuoteDetails($quoteId);
34+
            'quote' => $service->getQuoteDetails($quoteId),
35-
        // TODO: Handle $apiResult->hasErrors
35+
        );
36-
        $quotePlan = $apiResult->result;
36+
37
38-
        return array('form' => $form->createView(), 'quote' => $quotePlan);
38+