ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
PHP 用の HTMLテンプレート
日時: 2015/05/16 15:52
名前: lightbox



http://winofsql.jp/php/basic/log_01.php

何も表示されないテンプレート
拡張子:
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=600,initial-scale=1.0">

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function(){
	// ここに JavaScript のページの初期処理を記述
});
</script>
</head>

<body>
<!-- ここにコンテンツを作成する -->

</body>
</html>
メンテナンス

FORM から別ページの PHP を呼び出す ( No.1 )
日時: 2015/05/16 16:04
名前: lightbox


日時: 2015/05/16 16:04
名前: lightbox
http://winofsql.jp/php/basic/log_06.php

拡張子:
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=600,initial-scale=1.0">

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function(){

	// コンボボックスの選択されたテキストをテキストエリアにセットする
	$("#set_text").click(function(){
		$("#text").val( $("#action_file option:selected").text() );

	});

});
</script>
</head>

<body>
<!-- ここにコンテンツを作成する -->
<form method="POST"
	id="my_form"
	action="log_06a.php">
	<select name="php_file"
		id="action_file">
		<option value="log_02b.php"
			<?= $_GET["php_file"] == "log_02a.php" ? "selected" : "" ?> >連結演算子で文字列の連結
		</option>
		<option value="log_02b.php"
			<?= $_GET["php_file"] == "log_02b.php" ? "selected" : "" ?> >文字列内に変数を埋め込んで連結
		</option>
	</select>

	<br>件名 
	<input type="text"
		name="subject"
		id="subject">
	<input type="button"
		id="set_text"
		value="コンボボックスのテキストをセット">
	<br>
	<span style='vertical-align:top'>内容</span>
	<textarea name="text"
		id="text"
		style="width:400px;height:100px;"></textarea>
	<br>
	<input type="submit"
		name="send"
		value="送信">
</form>

</body>
</html>
log_06a.php
拡張子:
<?php
header( "Content-Type: text/html; Charset=utf-8" );

print "<pre>";
print_r($_GET);
print_r($_POST);
print "</pre>";

print "【連結演算子で文字列の連結】<hr>";

print $_POST["subject"] . $_POST["text"];

print "<hr>";
?>
<a href="log_06.php?php_file=<?= $_POST["php_file"] ?>">戻る</a>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
FORM の内容をファイルに出力する ( No.2 )
日時: 2015/05/16 16:07
名前: lightbox
http://winofsql.jp/php/basic/form/entry.php

拡張子:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=1280,initial-scale=1.0">
<style type="text/css">
body {
	line-height:150%;
	background-color: pink;
}
</style>

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
function checkForm() {

// ***********************************************
// DOM で書いた場合のサンプル
// ***********************************************
//	var sei = document.getElementsByName("sei")[0].value;
//	var sei = document.getElementById("sei").value;
//	var mei = document.getElementById("mei").value;

// ***********************************************
// jQuery で書いた場合のサンプル( 値の取り出し )
// ***********************************************
	var sei = $("#sei").val();
	var mei = $("#mei").val();

// ***********************************************
// jQuery で書いた場合のサンプル( 値のセット )
// ***********************************************
	$("#jyusyo").val("大阪府");

// ***********************************************
// デベロッパーツールへの出力( デバッグ用 )
// ***********************************************
	console.log( "姓 : " + sei );
	console.log( "名 : " + mei );

	// jQuery で一括表示
	$( $( "form" ).serializeArray() ).each(function(){
		console.log( this );
	});

// ***********************************************
// 未入力チェック
// ***********************************************
	if ( sei.trim() == "" ) {
		alert("氏名を入力して下さい");
		$("#sei").focus();
		return false;
	}

	return true;
}
</script>

</head>

<body>

<form method="POST"
	onsubmit="return checkForm();"
	action="result.php"
	target="result">氏名 

	<input type="text"
		name="sei"
		id="sei"
		style="width:100px">

	<input type="text"
		name="mei"
		id="mei"
		value="改行
しています"
		style="width:100px">

	<br>住所 
	<input type="text"
		name="jyusyo"
		id="jyusyo"
		style="width:240px">

	<br>性別 
	<select name="seibetu"
		id="seibetu">
		<option value="man">男</option>
		<option value="woman">女</option>
	</select>

	<br>
	<label for="in_check1">スマホ</label>
	<input type="checkbox"
		name="smh"
		id="in_check1"
		value="smh">

	<label for="in_check2">ガラケー</label>
	<input type="checkbox"
		name="gk"
		id="in_check2"
		value="gk">
	<br>

	<label for="in_radio1">有り</label>
	<input type="radio"
		name="in_radio"
		id="in_radio1"
		value="1"
		checked>
	<label for="in_radio2">無し</label>
	<input type="radio"
		name="in_radio"
		id="in_radio2"
		value="0">

	<br>備考 
	<br>
	<textarea name="bikou"
		id="bikou"
		style="width:320px;height:100px;"></textarea>

	<br>
	<input type="submit"
		name="send"
		value="送信">

</form>

<iframe
	src="about:blank"
	name="result"
	frameborder="1"
	scrolling="yes"
	width="600"
	height="400"
	style='border:solid 1px #000;margin-top:10px;'
></iframe>

</body>
</html>
result.php
拡張子:
<?php
header("Content-Type: text/html; charset=UTF-8");

// ***********************************************
// デバッグ表示
// ***********************************************
print "<pre>";
print_r( $_POST );
print "</pre>";

print "<hr>";

// ***********************************************
// ファイルに書き込む為の準備作業
// ***********************************************
$abc = $_POST["sei"] . "\n";
$abc .= $_POST["mei"] . "\n";
$abc .= $_POST["jyusyo"] . "\n";
$abc .= $_POST["seibetu"] . "\n";
$abc .= $_POST["smh"] . "\n";
$abc .= $_POST["gk"] . "\n";

// ***********************************************
// 実際の改行コードは変換して出力します
// ***********************************************
$work = str_replace("\r\n","\\r\\n",$_POST["bikou"]);
$work = str_replace("\n","\\n",$work);

$abc .= $work . "\n";

// ***********************************************
// ファイルへ書き込み
// ***********************************************
file_put_contents(
	"data.txt",
	$abc
);


// ***********************************************
// 表示( セキュリティ対策していません )
// ***********************************************
print $abc;

print "<hr>";

// ***********************************************
// HTML に埋め込む為の準備作業
// ( セキュリティ対策 )
// ***********************************************
$abc = str_replace("\"","&#34;",$abc);
$abc = str_replace("<","&lt;",$abc);
$abc = str_replace(">","&gt;",$abc);
?>

<input
	type="text"
	name="adr"
	value="<?= $abc ?>"
	style='width:320px;'>
<br>
<textarea
	style="width:320px;height:100px;"><?= $abc ?></textarea>
<br><br>
<a href="entry.php">戻る</a>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス