3

I have been following the ZendFramework documentation for file uploading found here: http://framework.zend.com/manual/2.1/en/modules/zend.form.file-upload.html

My problem is, when I try to submit the form when it is not valid I get the following error message:

Array provided to Escape helper, but flags do not allow recursion

Here is the code the the particular action in my controller:

public function addAction()
{
    $form = new TeamForm();
    $form->get('submit')->setValue('Add');

    $request = $this->getRequest();
    if ($request->isPost()) {
        $team = new Team();
        $form->setInputFilter($team->getInputFilter());
        $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
        $form->setData($post);

        if ($form->isValid()) {
            $files = $request->getFiles();
            $filter = new RenameUpload(array("target" => "./public/uploads/", "use_upload_extension"  => true, "randomize" => true));
            $fileinfo = $filter->filter($files['image']);
            $team->exchangeArray($form->getData());
            $team->image = basename($fileinfo["tmp_name"]);

            $this->getTeamTable()->saveTeam($team);

            return $this->redirect()->toRoute('team');
        }
    }
    return array('form' => $form);
}

I narrowed the error down to the following line:

$form->setData($post);

When I do a variable dump of $post, everything looks correct. After searching around the internet I haven't been able to find any answers as to why this happens.

I'd be happy to supply more information if necessary regarding this.

Thanks,

EDIT

Here is the view code

<?php
$form->setAttribute('action', $this->url('team', array('action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formInput($form->get('image'));
echo $this->formInput($form->get('name')
    ->setAttribute('class', 'large m-wrap')
    ->setAttribute('autocomplete', 'off')
    ->setAttribute('placeholder', 'Name'));
echo $this->formElementErrors($form->get('name'));
echo $this->formInput($form->get('title')
    ->setAttribute('class', 'large m-wrap')
    ->setAttribute('autocomplete', 'off')
    ->setAttribute('placeholder', 'Title'));
echo $this->formElementErrors($form->get('title'));
echo $this->formSubmit($form->get('submit')
    ->setAttribute('class', 'btn green'));
echo $this->form()->closeTag();
?>
1
  • Could you paste the result of var_dump($post); just before $form->setData($post);, please? Commented Oct 15, 2013 at 13:02

3 Answers 3

2

Problem is in your view file please use

<?php echo $this->formFile($form->get('image')); ?>

instead of

echo $this->formInput($form->get('image'));

for file type it should be $this->formFile()

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

Comments

0

The problem is not in the controller but in the view. You are passing an array to the view helper escape() instead of a string.

1 Comment

Hi jackflash, I just added the code of my view in an edit to my post. I am aware $_POST contains an array in this case, but the official Zend tutorial is saying to do it this way. Am I missing something?
-1

I think the problem is the line above, do an array_merge rather than a recursive merge.

2 Comments

What are you basing on?
Having done the same thing last week, despite the docs saying to merge recursively, I have had more luck NOT doing it that way.

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.