开发者

Symfony: form field access with no sfForm object

开发者 https://www.devze.com 2023-04-11 20:16 出处:网络
i\'m working on a symfony project and i developed a form to upload a file and save its info to a table in my model. And didn\'t use the sfForm class to implement my form.

i'm working on a symfony project and i developed a form to upload a file and save its info to a table in my model. And didn't use the sfForm class to implement my form. Here you have my form

<form name="new_file" action="<?php echo url_for('home/uploadFile');?>" method="post">
    <input type="file" id="file">
    <input  value="<?php echo $codigo_maestro?>" id="master_id">
    <input  value="<?php echo $codigo_entidad?>" id="entity_id">
    <input type="sub开发者_开发知识库mit" value="Upload">
</form>

So now i'm trying to access the fields of the sumbited form in my action function and don't know how :(

$request->getParameter('file');
$request->getParameter('master_id');
$request->getParameter('entity_id');

this code didn't work. So please help me solve this! How can i access the fields of my form from the action??


You need to add a name to your form fields, that's the name you can access them via $request->getParameter().


finally i did this way, maybe not most elegant, but working

in action.class.php
   $file= $_FILES['file'];
   $filesize = $archivo['size'];
   $filetype = $archivo['type'];
   $filename = str_replace(' ','-',$file['name']);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号