Forms

Hy

When I filled out the form and I click on the button validate it return me to the index page of my site I do not know from where it comes but I think the error comes for wampserver   if you have an idea do not hesitate to explain to me please.

Thank you

First shows us the code that handles form submission. Without code we can only guess.

  • Action attribute of the form is messed up?

  • Routes are wrong?



577

this is my view : {{ content() }} <ul class="pager">

    <li class="previous pull-left">
        {{ link_to("itk/search", "&larr; Retour") }}
    </li>
    <li class="pull-right">
    </li>
</ul>

<h3>Nouvelle intervention</h3>

<div class="well"> {{ form(" itk/create", 'class': 'form-horizontal') }} <fieldset> {% for element in form %} {% if isa(element, 'Phalcon\Forms\Element\Hidden') %} {{ element }} {% else %} <div class="form-group"> {{ element.label(['class': 'col-sm-4 control-label']) }} <div class="col-sm-4"> {{ element.render(['class': 'form-control', 'rows': '' ]) }} </div> </div> {% endif %} {% endfor %} </fieldset> <div class="form-group"> {{ submitbutton("Sauvegarder", "class": "btn btn-success") }} </div> </form> </div>

this is my function createAction():

    if (!$this->request->isPost()) {
        return $this->forward("itk/recherche");
    }

    $form = new ItkForm;
    $itk = new Itk();


    $data = $this->request->getPost();
    if (!$form->isValid($data, $itk)) {
        foreach ($form->getMessages() as $message) {
            $this->flash->error($message);
        }
        return $this->forward('itk/new');
    }

    if ($itk->save() == false) {
        foreach ($itk->getMessages() as $message) {
            $this->flash->error($message);
        }
        return $this->forward('itk/new');
    }

    $form->clear();

    $this->flash->success("Intervention créée avec succès");
    return $this->forward("itk/search");

thank you

edited Aug '16

I would start debugging line by line in your createAction() to see if the problem is there.

Start by adding die("here") on top of the method, then move it after each line and see where it stops to print 'HERE' this way you will find where you are getting redirected.

If nothing happens check if you have something that executes before this controller i.e. parent controller check redirects?