LoginSignup
4
7

More than 3 years have passed since last update.

contact form 7 にPOSTで値を渡す

Last updated at Posted at 2019-06-15

最近の業務の5%くらいは、WordPressで構築されたサイトのバグ修正とか機能追加をやっています。
Contact Form 7 に値を渡す際に、URLパラメーターとして値を渡す記事はたくさんあるのですが、POSTで渡す記事がちゃんとなかったのでメモがてら残します。

single.php
// 例えば、single.phpとかに以下を書く
<form action="contact form 7で構築したページのURL" method="post" name="form1">
    <input type="hidden" name="hogehoge" value="渡す値">
    <a href="javascript:form1.submit()">fugafuga</a>
</form>
function.php
// function.phpに以下を書く
  function my_form_tag_filter($tag){
    if (!is_array($tag)){
      return $tag;
    }

    if(isset($_POST['hogehoge'])){
    $name = $tag['name'];
    if($name == 'hogehoge')
      $tag['values'] = (array) $_POST['hogehoge'];
    }

    return $tag;
  }
  add_filter('wpcf7_form_tag', 'my_form_tag_filter');
// Contact Form 7内の設定で、以下で取得
[text* hogehoge default:post class:readonly readonly]

hogehogedefault:post以外は、用途に合わせて変更してください。

参考

『ContactForm7』GET/POSTでデータ送受信のメソッド的なもの

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7