Form Builder -> files

edited March 2013 in Bug Reports
Hi!

Okay, working in the front end and I need to produce a standard form which is easy enough. But for some reason when I'm trying to add a file upload field to it, it's not working for me. I'm wondering where I've gone wrong.

Here's the code in my controller:$fields = array(); $upload_path = assets_server_path().'uploads/'; $fields['name'] = array('required' => TRUE, 'label' => 'Your Name','class' => 'required" minlength="2'); $fields['email'] = array('required' => TRUE, 'class' => 'required email" autocapitalize="off" autocorrect="off'); $fields['phone'] = array('required' => TRUE, 'class' => 'required phone'); $fields['drawings'] = array('label' => 'Drawings','type' => 'file', 'allow' => 'pdf,ai,dwg','multiple' => TRUE, 'upload_path' => $upload_path); //$fields['message'] = array('type' => 'textarea', 'cols' => 45,'required' => TRUE, 'class' => 'textarea', 'class' => 'required'); $this->form_builder->set_fields($fields); // will set the values of the fields if there is an error... must be after set_fields $this->form_builder->set_validator($this->validator); $this->form_builder->form_attrs = 'data-ajax="false" action="" id="request_form" method="POST"'; $this->form_builder->set_field_values($_POST); $this->form_builder->display_errors = TRUE; $this->form_builder->required_indicator = ''; $this->form_builder->label_layout = 'top'; $this->form_builder->submit_value = '<input type="submit" value="Send" name="submit" data-inline="true" data-theme="d" >'; $this->form_builder->id = 'form'; $vars['form'] = $this->form_builder->render(); // use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing $this->fuel->pages->render('request', $vars,array('render_mode' => 'cms'));
  1. The multiple field isn't showing up. It only allows for 1 file at a time dynamically.
  2. The file is not showing up in the path specified
There are no JavaScript errors which one would figure would be causing the multiple option to not work.
Any ideas?

I have just updated my form_builder.php file in the fuel module library folder.

Thanks :)

Comments

  • edited 5:18AM
    On the same note. How would I be able to add a tag to the label? Ie a 'title' or 'data-title' for tool-tips?
    I could do it easily enough in the JavaScript, but wanted it more self-contained.
  • edited 5:18AM
    Is this in the 1.0 beta? If so, add the following:
    $this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');
    There is a "data" type attribute you can use which takes an array of "data" type attributes to append to the element.
  • edited 5:18AM
    Any thoughts on the first post then?
  • edited 5:18AM
    Oh! I got it now :)
    And it was right there in the instructions I was staring at... sheesh.
  • edited 5:18AM
    I found all my answers. I'd like to make a few notes about using Form_Builder on the front end here if I may for future reference (and since we are unable to add notes to the User Guide yet).
    • For using Form Builder in your controller/view files not in the CMS You must include the following in the header of the page:
      <script type="text/javascript"> var jqx_config = {}; jqx_config.localized = {"label_search":"Search...","btn_save":"Save","btn_cancel":"Cancel","btn_add":"Add","btn_edit":"Edit","btn_select":"Select","btn_asset":"Asset","btn_image":"Image","btn_pdf":"PDF","btn_flash":"Flash","btn_upload_asset":"Upload Asset","btn_view_source":"Source","btn_view_editor":"Editor","btn_preview":"Preview","btn_select_all":"Select All","btn_deselect_all":"Deselect All","comboselect_values_empty":"There are no more values to select","comboselect_selected_empty":"Select from the values on the left","comboselect_filter":"Filter your search","tree_orphans":"_orphans","confirm_delete":"Are you sure you want to delete this?","form_label_send_email_notification":"Send password update email notification?","error_importing_ajax":"Error importing view file","viewpage_close":"Close","viewpage_new_window":"New Window","rearrange_on":"You can change the precedence order by selecting and dragging the data rows below.","replace_warning":"Are you sure you want to replace the contents of this record?","edit_multi_select_warning":"You must have only have one option selected to edit.","markitup_b":"Bold","markitup_i":"Italic","markitup_strike":"Stroke Through","markitup_p":"Paragraph","markitup_h1":"Heading 1","markitup_h2":"Heading 2","markitup_h3":"Heading 3","markitup_h4":"Heading 4","markitup_ul":"Bullet List","markitup_ol":"Numeric List","markitup_li":"List Item","markitup_blockquote":"Block Quote","markitup_hr":"Horizontal Rule","markitup_img":"Image","markitup_link":"Link","markitup_target":"Target","markitup_title":"Title","markitup_mailto":"Mailto","markitup_php":"PHP Variable","markitup_clean":"Clean","markitup_preview":"Preview Toggle (hold down alt\/option and click to preview)","markitup_fullscreen":"Full Screen","markitup_placeholder_headings":"Your title here...","markitup_placeholder_link":"Your text to link...","markitup_email":"email@address.com","markitup_fullscreen_close":"Close","warn_before_delete_msg":"Are you sure you want to delete this item?","btn_add_another":"Add Another","btn_remove":"Remove"}; var __FUEL_LOCALIZED__ = {"label_search":"Search...","btn_save":"Save","btn_cancel":"Cancel","btn_add":"Add","btn_edit":"Edit","btn_select":"Select","btn_asset":"Asset","btn_image":"Image","btn_pdf":"PDF","btn_flash":"Flash","btn_upload_asset":"Upload Asset","btn_view_source":"Source","btn_view_editor":"Editor","btn_preview":"Preview","btn_select_all":"Select All","btn_deselect_all":"Deselect All","comboselect_values_empty":"There are no more values to select","comboselect_selected_empty":"Select from the values on the left","comboselect_filter":"Filter your search","tree_orphans":"_orphans","confirm_delete":"Are you sure you want to delete this?","form_label_send_email_notification":"Send password update email notification?","error_importing_ajax":"Error importing view file","viewpage_close":"Close","viewpage_new_window":"New Window","rearrange_on":"You can change the precedence order by selecting and dragging the data rows below.","replace_warning":"Are you sure you want to replace the contents of this record?","edit_multi_select_warning":"You must have only have one option selected to edit.","markitup_b":"Bold","markitup_i":"Italic","markitup_strike":"Stroke Through","markitup_p":"Paragraph","markitup_h1":"Heading 1","markitup_h2":"Heading 2","markitup_h3":"Heading 3","markitup_h4":"Heading 4","markitup_ul":"Bullet List","markitup_ol":"Numeric List","markitup_li":"List Item","markitup_blockquote":"Block Quote","markitup_hr":"Horizontal Rule","markitup_img":"Image","markitup_link":"Link","markitup_target":"Target","markitup_title":"Title","markitup_mailto":"Mailto","markitup_php":"PHP Variable","markitup_clean":"Clean","markitup_preview":"Preview Toggle (hold down alt\/option and click to preview)","markitup_fullscreen":"Full Screen","markitup_placeholder_headings":"Your title here...","markitup_placeholder_link":"Your text to link...","markitup_email":"email@address.com","markitup_fullscreen_close":"Close","warn_before_delete_msg":"Are you sure you want to delete this item?","btn_add_another":"Add Another","btn_remove":"Remove"}; jqx_config.assetsAccept = 'jpg|jpeg|gif|png'; jqx_config.editor = 'markitup'; // if you use the texarea fields this must be named </script> <?=js(array('fuel' => 'jqx/jqx.js')).js(array('fuel' => 'fuel/global.js')).js(array('fuel' => 'jquery/plugins/jquery.form'))?>
      I would suggest adding that in an if statement which determines if the page NEEDS to use the forms. ie. if (strtolower(uri_segment(1)) == 'formpage')
    • The form builder 'comment' option ads a <span> tag in the <label> tag with a title="" which you can reference with a tooltip jQuery app. (I know, it says in the docs, but it wasn't very clear, and it took a while to figure it out for me.)

    I love that as I'm learning more it's coming together so much easier. The learning curve is huge, but the payoff is incredible!

    Again, thanks for sharing Fuel David!
  • edited 5:18AM
    The javascript does get a bit messy once you venture outside of the CMS. I made a couple updates to help make it a little easier. The following should provide the JS you need.
    <script> <?php $this->load->module_view(FUEL_FOLDER, '_blocks/fuel_header_jqx'); ?> </script> <?php echo js('fuel/global', 'fuel')?> <?php echo js('jquery/plugins/jquery-ui-1.8.17.custom.min', 'fuel'); ?>

    Below is the CSS that may need to be included:
    <?=css('jqmodal, jquery.tooltip, jquery.treeview, fuel-theme/jquery-ui-1.8.17.custom, fuel', 'fuel')?>
  • edited March 2013
    Cool.

    Umm, I found a problem with the way I was using custom_fields.php. Is there a specific spot to put my own custom field types, or should they just go in fuel\modules\fuel\libraries\Fuel_custom_fields.php ?

    It was working on the front end PERFECTLY the way I had it, but as soon as I try to use the back end it messed up the forms section terribly. :(

    I tried creating \fuel\application\libraries\MY_custom_fields.php but even with my custom_field as such: $fields['request_checkbox'] = array( 'class' => array('app' => 'libraries/MY_custom_fields'), 'css_class' => 'request_checkbox', 'function' => 'request_checkbox' );
    it couldn't find the class in the libraries section.

    I put my function in Fuel_custom_fields.php like such: function request_checkbox($params) { $form_builder =& $params['instance']; $str = $form_builder->create_checkbox($params).' <label for="'.$params['name'].'">'.$params['label'].'</label><br /><br />'; return $str; }

    And this comes up with some frustrating errors.

    Is there's a better way?

    thanks.
  • edited 5:18AM
    Okay, so I think I solved it.

    I put my functions in my controller file outside of the class and removed the $fields[] array in MY_custom_fields.php

    Seems okay so far.
  • edited 5:18AM
    I think there may be some confusion as to where that config information needs to go. I just noticed that the documentation was incorrect as well and stated to add it to the $config['custom_fields'] array in the fuel/application/config/custom_fields.php config file (should just be the $fields array).
    $fields['request_checkbox'] = array(
    'class' => array('app' => 'libraries/MY_custom_fields'),
    'css_class' => 'request_checkbox',
    'function' => 'request_checkbox'
    );
Sign In or Register to comment.