formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Problem showing uploaded filenames #908

Open MajorHeadache opened 1 year ago

MajorHeadache commented 1 year ago

I'm trying to update a multi-form submission from API v1 to API v2. In API v1 the following code would work when navigating back to the initial form. (It would show the name of the file that was uploaded, or if you hadn't uploaded one it allowed you to.)

\<?php if(isset($fields['pdfupload'])) echo $fields['pdfupload']['filename']; else echo ''; \?>

In API v2 the echo statement does not show the filename any more. Has the syntax changed or is there a newer, better way to accomplish this?

jweese74 commented 1 year ago

Based on my understanding of Form Tools API v2 and your provided code snippet, I'm guessing that the issue might be due to a change in the way form field values are accessed. You can try updating your code snippet as follows:

if (isset($form_data['pdfupload'])) { echo $form_data['pdfupload']['filename']; } else { echo ''; }

Keep in mind, I don't mess with the API too terribly much, especially API v1, but this should be relatively correct.

Jeff

On Wed, May 10, 2023 at 8:49 PM MajorHeadache @.***> wrote:

I'm trying to update a multi-form submission from API v1 to API v2. In API v1 the following code would work when navigating back to the initial form. (It would show the name of the file that was uploaded, or if you hadn't uploaded one it allowed you to.)

<?php if(isset($fields['pdfupload'])) echo $fields['pdfupload']['filename']; else echo ''; ?>

In API v2 the echo statement does not show the filename any more. Has the syntax changed or is there a newer, better way to accomplish this?

— Reply to this email directly, view it on GitHub https://github.com/formtools/core/issues/908, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACED2LSJGYTVCATQ27U5I6TXFQZQVANCNFSM6AAAAAAX5MWJQQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Jeff Weese

MajorHeadache commented 1 year ago

I tried the code snippet, but it doesn't work as expected. Looks like $form_data is null. Do I need to do something to assign values to that variable? Here is the code snippet I use at the top of the page:

require_once("formtools/global/api/API.class.php"); $api = new FormTools\API(); $fields = $api->initFormPage(2); $params = array( "submit_button" => "continue_button", "next_page" => "review.php", "form_data" => $_POST, "file_data" => $_FILES ); $api->processFormSubmission($params);

Thanks in advance for your help.

jweese74 commented 1 year ago

I want to clarify that my knowledge of the specifics of the Form Tools API v1 and v2 is theoretical, as I do not personally use or test these APIs. However, based on typical programming patterns and practices, the logic in the provided solution should be sound.

Please try replacing $form_data with $fields in your if statement, as in the following code:

if (isset($fields['pdfupload'])) {
    echo $fields['pdfupload']['filename'];
} else {
    echo '';
}

In this code, $fields should contain the form data, so checking for 'pdfupload' in $fields and then echoing the filename should give you the desired outcome.

This is just a suggested solution based on the information provided and my understanding of PHP and APIs.