Home › Forums › Quform WordPress › How to save a form forlater › Reply To: How to save a form forlater
Hi,
Thank you for your reply, however I don’t save in the cookies as in the documentation but in the database in a personal encrypted table.
However, I have another problem, much more serious at the moment, I want to display the form I’ve already submitted but the information isn’t coming back correctly, in fact the classic fields are coming back but there are problems with the files and checkboxes, can you help me? Here’s a code snippet:
add_action(‘quform_pre_display_’ . $form_id, function (Quform_Form $form) {
//We get last send value
global $currentForm;
if ($currentForm && is_array($currentForm)) {
foreach ($currentForm as $res) {
$form->setValue(
“quform_” . $res->form_id . “_” . $res->element_id,
is_serialized($res->value) ? unserialize(quform_set_value_from_storage($res->value)) : quform_set_value_from_storage($res->value)
);
if ($form->getElement(“quform_” . $res->form_id . “_” . $res->element_id) instanceof Quform_Element_File) {
$values = [];
var_dump(unserialize(quform_set_value_from_storage($res->value)));
foreach (unserialize(quform_set_value_from_storage($res->value)) as $key => $arr) {
foreach ($arr as $k => $a) {
$values[$k][] = $a;
}
$values[“error”][$key] = 0;
}
$_FILES[“quform_” . $res->form_id . “_” . $res->element_id] = $values;
}
}
} else {
global $wpdb;
$form_id = get_field(‘form_used_id’, ‘option’) ? get_field(‘form_used_id’, ‘option’) : 1;
$user_id = get_current_user_id(); // Vous pouvez obtenir l’ID de l’utilisateur enregistré
// Vérifier si une ligne avec le même user_id existe déjà
$existing_row = $wpdb->get_row(“SELECT * FROM ” .$wpdb->prefix .”users_save_registration_step WHERE user_id = ” .$user_id .” AND form_id = ” .$form_id);
if ($existing_row) {
$existing_row->form_data = quform_set_value_from_storage($existing_row->form_data);
parse_str($existing_row->form_data, $values);
$form->setValues($values);
}
}
});