How to solve the "No file was uploaded." when trying to use custom form field? I get "No file uploaded" when I try to use a custom form in drupal .Below is the code which I have used to upload a file in drupal custom form.

    function mobiae_custom_purchase_order_form(&amp;$form,&amp;$form_state) {
      // Merge default values into the default array.
        $form = array();
          $form['#attributes']['enctype'] = 'multipart/form-data';

          $form['file'] = array(
            '#type' =&gt; 'file',
            '#title' =&gt; t('Image'),
            '#description' =&gt; t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
          );




      return $form;
    }


function mobiae_custom_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
  module_load_include('inc', 'mobiae_custom', 'mobiae_custom.purchase_order');
$form = array();
$form_state = array();
  // Default to a known test credit card number. For valid numbers of other card
  // types see: http://www.rimmkaufman.com/blog/credit-card-test-numbers/09112007/
//$form['#submit'][] = 'mobiae_custom_submit_form_validate';
  return mobiae_custom_purchase_order_form(&amp;$form, &amp;$form_state,$order); 
}

/**
 * Payment method callback: submit form validation.
 */
function mobiae_custom_submit_form_validate($payment_method, $pane_form, $pane_values, $order, $form_parents = array()) {
  // Validate the credit card fields.file_save
 drupal_set_message('fgh');
 $file = file_save_upload('file', array(
      'file_validate_is_image' =&gt; array(),
      'file_validate_extensions' =&gt; array('png gif jpg jpeg'),
  ));

  if ($file) {
    if ($file = file_move($file, 'public://')) {
      $pane_values['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('file', t('No file was uploaded.'));
  }

//  module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.credit_card');
  if (form_get_errors()){
    return false;
  }
}
For saving file u can use

    $form['test_picture']['file'] = array(
        '#type' =&gt; 'managed_file',
        '#title' =&gt; t('Test Picture'),
        '#description' =&gt; t('Allowed extensions: gif png jpg jpeg'),            
        '#upload_location' =&gt; variable_get('picture_upload_location'),
        '#upload_validators' =&gt; array(
            'file_validate_extensions' =&gt; array('pdf'),
            'file_validate_size' =&gt; array(MAX_FILE_SIZE*1024*1024),
        ),
    );