How to debug form without error

+
0
-

In my createComponentAddRecipeForm function I have

<?php
 $form->onSuccess[] = [$this, 'addRecipeFormSucceeded'];
?>

In addRecipeFormSucceeded I have the following:

<?php
        public function addRecipeFormSucceeded(Form $form, \stdClass $values)
        {
                if (!$this->getUser()->isAllowed('backend', 'add')) {
                        throw new Nette\Application\ForbiddenRequestException;
                }

                try {
                        $minutes = ($values->duration_hours*60) + $values->duration_minutes;
                        $arr = [];
                        $arr['user_id'] = $this->getUser()->getId();
                        $arr['title'] = $values->title;
                        $arr['description'] = $values->descrition;
                        $arr['duration'] = $minutes;
                        $arr['suitable_for_id'] = 1;
                        $arr['method'] = $values->method;
                        $arr['media_hero_id'] = 1;

                        $this->flashMessage("New Recipe Added", 'success');
                        $this->db->table('recipe')->insert( $arr );
                        $this->redirect('Admin:Recipe');

                } catch (Nette\Security\AuthenticationException $e) {
                        $form->addError('Add Recipe Category Failed'.$e->getMessage() );
                }
        }

?>

When the form is submitted, it goes back to the form with the fields filled in, except 2.
it seems the addRecipeFormSucceeded() method is never called.

there is no message,no error, so, how can I debug this?

CZechBoY
Member | 3608
+
0
-

How do you render it?

+
0
-

CZechBoY wrote:

How do you render it?

<form n:name=addRecipeForm class=form>

  <div class="row">
    <div class="large-12 columns">
      <label n:name=title>Title</label>
      <input n:name=title size=20>
    </div>
  </div> <!-- end row -->

 ... etc
<input n:name=send class="button success">
</form>
Phalanx
Member | 310
+
+1
-

Try to render errors in your form

<ul class="errors" n:if="$form->hasErrors()">
	<li n:foreach="$form->errors as $error">{$error}</li>
</ul>

Also you can use xDebug to catch what is wrong with this.

$form->onError[] = [$this, 'processPagesFormError'];


public function processPagesFormError(Form $form)
{

}

Last edited by Phalanx (2020-01-12 17:30)