0

I am theming the node add form in drupal 7 for a custom content type. I have proceeded as indicated here.

As a test I managed to write my custom tpl.php file and get everything displayed correctly as it was in the original version without that tpl.php file. One of the field in the form is a file which gets uploaded with file widget.

My problem with my new form is that: when I click the "Upload" button for the file field in my form I get the following error:

An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (128 MB) that this server supports.

But the file I am trying to upload is only about 100k!

I do not get this error when I use the regular form (i.e without using my custom tpl.php) file.

Here are the functions I implemented in my module:

/**                                                                                                                                                                                                                                     
 * implements hook_theme                                                                                                                                                                                                                
 *  to theme node add form                                                                                                                                                                                                              
 *                                                                                                                                                                                                                                      
 */
function mymodule_theme($existing, $type, $theme, $path) {
  return array(
               'mycontenttype_request_node_form' => array(
                                            'render element' => 'form',
                                            'template' => 'templates/mycontenttype-request-node-form',
                                            // this will set to module/theme path by default:                                                                                                                                           
                                            'path' => drupal_get_path('theme', 'bootstrap_subtheme'),
                                            ),
               );
  }


/**                                                                                                                                                                                                                                     
 * Preprocessor for theming ('mycontenttype_request_node_form').                                                                                                                                                                            
 *                                                                                                                                                                
 */

function mymodule_preprocess_softsound_request_node_form(&$variables) {


  $variables['myreq'] = array();
  $hidden = array();

    foreach(element_children($variables['form']) as $key) {
          $type = $variables['form'][$key]['#type'];
    if($type == 'hidden' || $type == 'token'){
      $hidden[]= drupal_render($variables['form'][$key]);
    }
    else {
      $variables['myreq'][$key] = drupal_render($variables['form'][$key]);
    }
  }

    //$variables['myreq']['hidden'] = implode($hidden);                                                                                                                                                                                 
    //$variables['myreq'] = implode($variables['myreq']);                                                                                                                                                                               

}

And here is my mycontenttype-request-node-form.tpl.php file:

 <div class="row-fluid">
    <div class="span8 offset2">
      <?php  print $myreq['title']; ?>
    </div>
  </div>

<div class="row-fluid">
    <div class="span8 offset2">
   <?php print $ssreq['field_description']; ?>
    </div>
  </div>


  <div class="row-fluid">
    <div class="span8 offset2" >
   <?php print $myreq['field_myfile']; ?>
    </div>
  </div>




  <div class="row-fluid">
    <div class="span8 offset2">
   <?php print $myreq['additional_settings']; ?>
    </div>
  </div>

  <div class="row-fluid">
    <div class="span8 offset2">
   <?php print $myreq['actions']; ?>
    </div>
  </div>


<?php print drupal_render_children($form); ?>

</div>

Any hints as to why I get the unrecoverable error relating to file size I mentioned above and how to get rid of it?

Thanks,

baba

0

The problem was that i called drupal render on all elements of the form in my preprocess function and that I also called drupal_render_children in my tpl. This was redundant and caused errors.

my preprocess function now reads:

function mymodule_preprocess_softsound_request_node_form(&$variables) {


   $variables['myreq'] = array();

  $variables['myreq']['title'] = drupal_render($variables['form']['title']);
  $variables['myreq']['field_description'] = drupal_render($variables['form']['field_description']);
  $variables['myreq']['field_myfile'] = drupal_render($variables['form']['field_wavfile']);


}

and my tpl.php now reads:

<div class="row-fluid"  >
      <div class="span8 offset2" >
           <?php print $myreq['title']; ?>
           <?php print $myreq['field_description']; ?>
       </div>
  </div>


  <div class="row-fluid">
    <div class="span8 offset2" >
   <?php print $myreq['field_myfile']; ?>
    </div>
  </div>



<?php print drupal_render_children($form); ?>


</div>

thanks to Rashad Majali for the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.