質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

1回答

3716閲覧

WordPress、PHPの$_POSTの入力値チェックについて。

matometaru

総合スコア43

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2017/02/17 03:53

いつもありがとうございます。

下記の行がサニタイズ≒値チェックできてないとのことですが、保存するデータはそれ以降の行でチェックを行っているつもりです。下記の行について、どういった処理が必要でしょうか?

$this->options = $_POST[$this->text_domain];

That sets your option name to be a NON sanitized value.

php

1 2function admin_setting_form() { 3 $post_types = wp_list_filter( get_post_types(array('public'=>true)),array('attachment'), 'NOT' ); 4 ?> 5 <div class="wrap"> 6 <h2><?php echo esc_attr($this->name); ?> &raquo; <?php _e('Settings'); ?></h2> 7 <form id="<?php echo esc_attr($this->text_domain); ?>" method="post" action=""> 8 <?php wp_nonce_field( 'csr-nonce-key', 'csr-key' ); ?> 9 <h3><?php _e('有効にする投稿タイプを選択してください'); ?></h3> 10 <?php 11 foreach ( $post_types as $post_type ) { 12 ?> 13 <p> 14 <strong><?php echo esc_attr($post_type); ?>ページ上で有効にします</strong> 15 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[post_type][<?php echo esc_attr($post_type); ?>]" value="1" <?php if( isset( $this->options['post_type'][$post_type] ) && $this->options['post_type'][$post_type] == '1' ) echo 'checked'; ?> /> 16 </p> 17 <?php 18 } 19 ?> 20 <h3>コメントの入力から外したい要素を選択</h3> 21 <p> 22 <strong>URLを外す</strong> 23 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[url]" value="1" <?php if( isset( $this->options['url'] ) && $this->options['url'] == '1' ) echo 'checked'; ?> /> 24 </p> 25 <p> 26 <strong>メールアドレスを外す</strong> 27 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[email]" value="1" <?php if( isset( $this->options['email'] ) && $this->options['email'] == '1' ) echo 'checked'; ?> /> 28 </p> 29 <p class="submit"> 30 <input class="button-primary" type="submit" name='save' value='<?php _e('Save Changes') ?>' /> 31 </p> 32 </form> 33 </div> 34 <?php 35} 36// save 37function admin_save_options() { 38 $post_types = wp_list_filter( get_post_types(array('public'=>true)),array('attachment'), 'NOT' ); 39 if (isset($_POST['save'])) { 40 if( check_admin_referer( 'csr-nonce-key', 'csr-key' ) ) { 41 if (isset($_POST[$this->text_domain]) && is_array($_POST[$this->text_domain]) ) { 42 $this->options = $_POST[$this->text_domain]; 43 // post_type sanitai 44 foreach ( $post_types as $post_type ) { 45 if( isset($this->options['post_type'][$post_type]) ) { 46 $this->options['post_type'][$post_type] = '1'; 47 } 48 } 49 if( isset( $this->options['url'] ) && $this->options['url'] == '1' ) { 50 $this->options['url'] = '1'; 51 } 52 if( isset( $this->options['email'] ) && $this->options['email'] == '1' ) { 53 $this->options['email'] = '1'; 54 } 55 update_option($this->text_domain, $this->options ); 56 } 57 //wp_safe_redirect( menu_page_url( $this->text_domain, false ) ); 58 } 59 } 60 $this->options = get_option($this->text_domain); 61 $this->admin_setting_form(); 62}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

filter_input()が手軽でラクかと

投稿2017/02/17 04:34

yambejp

総合スコア114773

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

matometaru

2017/02/17 16:55

ありがとうございます。しかし、 Warning: filter_input() expects parameter 2 to be string, array given in となりました。 if (isset($_POST[$this->text_domain]) && is_array($_POST[$this->text_domain]) ) { ひとつ前のこのチェックではだめなのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問