ワードプレスの有名なフォーム用プラグインであるMW WP Formで、郵便番号を入力すると、住所が自動入力されるようにする方法です。
■ajaxzip3の読み込み
functions.php内に
1 2 3 4 5 |
<?php function ajaxzip3_scripts() { wp_enqueue_script( 'ajaxzip3-script', 'https://ajaxzip3.googlecode.com/svn/trunk/ajaxzip3/ajaxzip3-https.js', array( 'jquery' ), '20140807', true ); } add_action( 'wp_enqueue_scripts', 'ajaxzip3_scripts' ); |
■フォーム内で動かす設定
1 2 3 4 5 6 7 |
<script type="text/javascript"> jQuery(function( $ ) { jQuery( 'input[name="zip2"]' ).keyup( function( e ) { AjaxZip3.zip2addr('zip1','zip2','address1','address2'); } ) } ); </script> |
■自動入力させるフォームの設定
1 2 3 4 5 6 7 |
郵便番号 [mwform_text name="zip1" id="zip1" size="10" placeholder="半角英数" conv_half_alphanumeric="true"]-[mwform_text name="zip2" id="zip2" size="10" placeholder="半角英数" conv_half_alphanumeric="true"] 都道府県 [mwform_text name="address1" id="address1"] 市区町村 [mwform_text name="address2" id="address2" size="10" ] </dd></dl> |
コメント