eZ Community » Forums » eZ Publish 5 Platform » form enctype="multipart/form-data"...
expandshrink

form enctype="multipart/form-data" conflicting with $contentService->publishVersion: Missing form token from Request

form enctype="multipart/form-data" conflicting with $contentService->publishVersion: Missing form token from Request

Sunday 15 December 2013 5:47:52 pm - 3 replies

Hi

I am trying to create a symfony form that uploads an image and then creates an image content object.

So, this is my simple bundle:

https://github.com/thiagocamposviana/tuteiformsbundle

After I login as admin user, I go to /tutei/forms/2 , where 2 is the parent location id of the image object to be created. So, twig creates the following html:

<form action="/tutei/forms/2" method="post" enctype="multipart/form-data">
<div id="form">
<div>
<label for="form_name" class="required">Name</label>
<input type="text" id="form_name" name="form[name]" required="required" />
</div>
<div>
<label for="form_image" class="required">Image</label>
<input type="file" id="form_image" name="form[image]" required="required" />
</div>
<input type="hidden" id="form_ezxform_token" name="form[ezxform_token]" value="e44d07885e70ea3d48ce2bb644e10f5e4141d370" />
</div>
<input type="submit" />
</form>

After I fill the name field with a text and choose one image to the file field and press the submit button, everything goes well with my code until it calls the function $contentService->publishVersion(...), this causes the following error:

 

Missing form token from Request

Any ideas if this is a bug?

I also tried to use:

$formOptions = array( 'intention' => 'legacy' );

 

As specified at: https://confluence.ez.no/display/EZP52/Legacy+configuration+injection?src=search

But this doesn't solve the problem. If I use a normal form, without files, without enctype, it looks ok, but I want to upload a file, so I need to specify enctype as multipart/form-data.

Could anyone help me?

Edited:

I created a workaround to make this work:

https://github.com/thiagocamposviana/tuteiformsbundle/tree/workaround

In this case I save the uploaded info and files in a cache folder, then I redirect to another page that will process the form, so I don't have this missing token problem, but I still don't know why I have that problem in the first place.

Modified on Sunday 15 December 2013 9:11:04 pm by Thiago Campos Viana

Monday 16 December 2013 10:22:05 am

Hi Thiago

In your template example, it seems that you don't use the form views from the form component... I guess this might be related happy.gif Emoticon.

Monday 16 December 2013 10:52:12 am

Quote from Jérôme Vieilledent :

Hi Thiago

In your template example, it seems that you don't use the form views from the form component... I guess this might be related happy.gif Emoticon.

Hi Jérôme

This is the code used in the template https://github.com/thiagocamposviana/TuteiFormsBundle/blob/master/Resources/views/Default/index.html.twig

 

<form action="{{path( 'tutei_forms_homepage', {locationId:locationId} )}}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<input type="submit" />
</form>

This outputs the html showed in my opening post, is there a better way to do this? I am not that used with symofny2.

Edited: looks like a bug to me, if form enctype="multipart/form-data",  ezxFormToken ::input will not recognize form[ezxform_token].

Modified on Monday 16 December 2013 4:28:12 pm by Thiago Campos Viana

Monday 16 December 2013 4:33:31 pm

Just did a test, if I remove the ezxform_token hidden field that is automatically generated in the form with firebug, then the form works.

Edited:

If I use jquery to remove the form token hidden field:

    $(document).ready( function(){
        $("#form_ezxform_token").remove();
        
    });

Then it also works.

Edited 2: Changed git repository, I am loading a new action and saving all the data inside a cache folder, so I don't care about this problem.

Modified on Monday 16 December 2013 7:19:08 pm by Thiago Campos Viana

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from