Skip to content

Instantly share code, notes, and snippets.

@hissy
Created November 11, 2013 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/7409451 to your computer and use it in GitHub Desktop.
Save hissy/7409451 to your computer and use it in GitHub Desktop.
[WordPress/Trust Form] 一部の入力フィールドの値をcookieに保存し、次回入力時に読み込む
<?php
function save_trustform_default_value() {
if (isset($_REQUEST['tr_default_3']) && $_REQUEST['tr_default_3'] == 1) {
$data = array();
$trust_form = new Trust_Form_Front(3);
$col_name = $trust_form->get_col_name();
foreach ( $col_name as $key => $name ) {
if ($name == '保存したいフィールドのラベル') {
$data[$key] = stripslashes_deep($_POST[$key]);
}
}
setcookie('wordpress_tr_default_3', serialize($data), time()+3600);
}
}
add_action( 'wp_loaded', 'save_trustform_default_value' );
<?php
function trust_form_show_input() {
global $trust_form;
$col_name = $trust_form->get_col_name();
$validate = $trust_form->get_validate();
$config = $trust_form->get_config();
$attention = $trust_form->get_attention();
// set default value from cookie
$data = unserialize( stripslashes_deep($_COOKIE['wordpress_tr_default_3']) );
if (isset($data) && is_array($data)) {
foreach ($data as $key => $name) {
$_POST[$key] = esc_attr($name);
}
}
$nonce = wp_nonce_field('trust_form','trust_form_input_nonce_field');
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment