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