1

I am working on upload contact form 7. Client can save his input filed form process and upload it when ever he needs the same fields to be filled.

I was able to save form input values in a .dat file. Now on upload in my form page I am storing this field in a session. And the trouble that I am having is, how to pass that session values to a form inputs.

For example, I created this code:

if(!empty($_SESSION['uploaded_file_data']) && is_array($_SESSION['uploaded_file_data'])){
    foreach ($_SESSION['uploaded_file_data'] as $key => $value){
        $_POST[$key] = $value;
    }

    unset($_SESSION['uploaded_file_data']);
}

where $_SESSION['uploaded_file_data'] data with

var_dump($_SESSION['uploaded_file_data'])

looks like this:

array (
'_wpcf7' => '2899',
'_wpcf7_version' => '5.0.5',
'_wpcf7_locale' => 'en_US',
'_wpcf7_unit_tag' => 'wpcf7-f2899-o1',
'_wpcf7_container_post' => '0',
'_wpcf7cf_hidden_group_fields' => '[]',
'_wpcf7cf_hidden_groups' => '[]',
'_wpcf7cf_visible_groups' => '[]',
'_wpcf7cf_options' => '{"form_id":2899,"conditions":[],"settings":false}',
'gender' => 'Mr.',
'full_name_signatory_person' => 'Test Name',
'id_number_signature' => '1231111',
'company_name_signature' => 'Test Company',
'country_of_registration' => 'Test Country',
'registration_or_vat_number' => '23-886-BO',
'company_main_full_address' => 'Test Address',
'date' => '03 01 2019',
'gender2' => 'Mr.', ...

and so on. So the results are good, just need help figuring out why this $_POST[$key] = $value, is not adding a value to a input fields. What am I missing?

2 Answers2

0

Solved by setting the input field value with jQuery+php. For example:

$('[name="full_name_signatory_person"]').val("<?= $_POST['full_name_signatory_person'] ?>"); 

Not proud on this solution, but I could not find better way.

0

Please, consider improving your solution with this

<?php $full_name_signatory_person = filter_input(INPUT_POST, 'full_name_signatory_person', FILTER_SANITIZE_MAGIC_QUOTES); ?>

$('[name="full_name_signatory_person"]').val("<?= $full_name_signatory_person ?>");

Accessing superglobal variables - is not so good practice, please, use filter_input instead for preventing XSS atack.

When to use filter_input()