1

I am doing a lot on the page and I think I am getting a conflict somewhere. Basically, my page initially shows an input and a blank div. When an input is provided and submitted, the page refreshed with the div full of data. The user can then select some of this data and finally submit again.

This is my view

{% block main %}
    <div class="col-md-4">
        <section class="panel panel-default">
            <header class="panel-heading">
                <h3 class="panel-title">Terminal</h3>
            </header>

            <div class="panel-body">
                <form action="{{ path('NickAlertBundle_terminalSearch') }}" method="post" enctype="multipart/form-data" class="terminalForm" id="terminalForm">
                    <div class="row">
                        <div class="col-md-12">
                            <input type="text" class="addMargin" id="terminal_command" name="terminal_command" placeholder=">">
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-8 col-md-offset-4">
                            <input type="submit" class="btn btn-default" id="terminal_submit" value="Submit">
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>

    <div class="col-md-8" id="terminal-window">
        <table class="terminalAvailability">
            {% if data is defined %}
                <form action="{{ path('NickAlertBundle_terminalCreate') }}" method="post" enctype="multipart/form-data" class="terminalForm">
                    {% for info in data %}
                        <tr>
                            <td class="flightNumber">{{ info.flightNumber }}</td>
                            <td class="details">{{ info.from ~ info.to }}</td>
                            {% for seat, availability in info.seats %}
                                <td class="seatClass">
                                    <label for="{{ seat }}">
                                        <span>{{ seat ~ availability }}</span>
                                    </label>
                                    <input type="checkbox" id="{{ seat }}" name="seats[{{ info.flightNumber }}][]" style="display: none;" value="{{ seat }}" />
                                </td>
                            {% endfor %}
                            <td class="otherInfo">{{ info.other }}</td>
                        </tr>
                    {% endfor %}
                    <div class="row">
                        <div class="col-md-8 col-md-offset-4">
                            <input type="submit" class="btn btn-default" value="Submit">
                        </div>
                    </div>
                </form>
            {% endif %}
        </table>
    </div>

    <div class="modal"></div>
{% endblock %}

The first div is the input and the second div is the div the data will be displayed, selected, and resubmitted.

I then have my controller actions

public function terminalAction()
{
    return $this->render('NickAlertBundle:Page:terminal.html.twig');
}

public function terminalSearchAction(Request $request)
{
    try {
        $terminal_command = strtoupper($request->get('terminal_command'));

        $error = array();

        if (!$terminal_command) {
            $error[] = "Please enter the Command";
        }

        if (count($error)) {
            echo "There were errors adding the alert.\n\n";
            foreach ($error as $item) {
                echo $item . "\n";
            }
            die();
        }

        $uapiService = $this->container->get('alert_bundle.api_service');
        $commandData = $apiService->terminalService($terminal_command);

        return $this->render('NickAlertBundle:Page:terminal.html.twig', array(
            'data' => $commandData,
        ));

    }catch (Exception $e) {
    }
}

public function terminalCreateAction(Request $request)
{
    try {
        foreach ($request->request->get('seats') as $row) {
            foreach ($row as $seat) {
                var_dump($seat);
            }
        }
        return $this->render('NickAlertBundle:Page:terminal.html.twig');

    }catch (Exception $e) {
    }
}

And finally my routes

NickAlertBundle_terminal:
    pattern:  /terminal
    defaults: { _controller: NickAlertBundle:Alert:terminal }
    methods:  [GET]

NickAlertBundle_terminalSearch:
    pattern:  /terminal
    defaults: { _controller: NickAlertBundle:Alert:terminalSearch }
    methods:  [POST]

NickAlertBundle_terminalCreate:
    pattern:  /terminal
    defaults: { _controller: NickAlertBundle:Alert:terminalCreate }
    methods:  [POST]

So the page is initially displayed fine. The user then enters some input, submits it, and the response data is then displayed in the div. So this means the first two routes work perfectly. With the data in the div, the user can select some data, and then submit it. However, when this data is submitted, they are displayed with

There were errors adding the alert. Please enter the Command

This error is for the second action, and should not have anything to do with the third action. The second form has its path set to NickAlertBundle_terminalCreate so why would it cross wires with the other action?

Thanks

1 Answer 1

3

NickAlertBundle_terminalCreate will always solve to NickAlertBundle_terminalSearch, because the RouteMatcher will always match the pattern /terminal + method POST to the first route with these rules.

Why not give NickAlertBundle_terminalSearch a pattern like /terminal/search?

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

Comments

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.