简体   繁体   English

将会话中存储的值传递到联系表单 7 中的输入字段

[英]Pass values stored in session to an input field in contact form 7

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.我正在处理上传联系表单 7。客户可以保存他输入的表单流程,并在需要填写相同的字段时上传。

I was able to save form input values in a .dat file.我能够将表单输入值保存在 .dat 文件中。 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其中 $_SESSION['uploaded_file_data'] 数据与

var_dump($_SESSION['uploaded_file_data']) 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.所以结果很好,只需要帮助弄清楚为什么这个 $_POST[$key] = $value, 没有向输入字段添加值。 What am I missing?我错过了什么?

Solved by setting the input field value with jQuery+php.通过使用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.对这个解决方案并不感到自豪,但我找不到更好的方法。

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.访问超全局变量 - 不是很好的做法,请使用 filter_input 来防止 XSS 攻击。

When to use filter_input() 何时使用 filter_input()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM