PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Displaying uploaded file contents in a multipage form

  1. vladdie1979
    Member

    I posted this question in a brief form a few days ago at http://www.gravityhelp.com/forums/topic/displaying-uploaded-file-contents-before-submission , but it must have been overlooked by the gurus.
    So, once again.
    I am looking to implement the following:
    In a multipage form, the user uploads a plain text file at, say, 1st page. Presses "next page".
    Then the contents of the file is parsed by a custom function and populates a field/fields on the 2nd page.

    Here's what I tried:
    I have not found any hooks to grab the temporart uploaded file, so I hacked in a custom function call in the upload_files function in the form_display.php file, like this:

    file_contents_to_POST ($target_path, $file_info);

    The function does grab the file contents allright:

    function file_contents_to_POST ($filepath, $file_name_info) {
     if (pathinfo ($file_name_info ["temp_filename"], PATHINFO_EXTENSION) == "tmx") {	//check if it is a tmx-file
       $full_filename = $filepath . $file_name_info ["temp_filename"];
       $file_contents_object = new SimpleXMLElement (file_get_contents ($full_filename));
       $TU0 = $file_contents_object->{"body"}->{"tu"}[0]; //string
       $_POST ["TMX_file"] = $TU0;
     }
    }

    But I can't find a way to use the $_POST ["TMX_file"] contents to populate fields on the 2nd page.
    I tried the gform_field_value filter, the gform_pre_render filter. Doesn't work.
    So, I basically have two questions now:
    1) Am I taking a reasonable approach to grab the file contents? Or is there a simpler way to do what I'm aimimg at.
    2) Why are the filters not getting the $_POST contents? What am I doing wrong here? Should I store the file contents in a different way instead of $_POST?

    Thanks in advance

    Posted 12 years ago on Wednesday October 26, 2011 | Permalink
  2. Hi Vladdie,

    You actually don't have to mess with the core code at all. You can get the contents of the file right from the gform_pre_render hook (and potentially the gform_field_value hook, didn't test that though). Here is some sample code:

    http://pastie.org/2764573

    Posted 12 years ago on Wednesday October 26, 2011 | Permalink
  3. vladdie1979
    Member

    David, thank you so much!
    The default values are pre-filled like a snap now with the gform_pre_render hook.
    Sadly, the approach you suggested to get temp file contents (via RGFormsModel::get_upload_path and RGFormsModel::get_temp_filename ) is not documented.

    Posted 12 years ago on Thursday October 27, 2011 | Permalink
  4. Hi Vladdie,

    Unfortunately we can't document every line of code in Gravity Forms but we're always more than happy to point the way when asked. Glad you were able to get this working! :)

    Posted 12 years ago on Friday October 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.