 |
|
|  |
PHP À̸§ÀÌ °°Àº Æûű×(Form Tag)ÀÇ °ª(value) ó¸®Çϱâ |
|
|
 |
13³â Àü |
Æûű×(<form></form>)³»¿¡ ÀÖ´Â INPUT ű×(INPUT BOX), üũ¹Ú½º ű×(CHECK BOX) µîµî¿¡ µ¿ÀÏÇÑ À̸§ÀÌ »ç¿ëµÈ °æ¿ì PHP¿¡¼´Â ASP, JSP ¿Í´Â Á» ´Ù¸£°Ô 󸮸¦ ÇØÁà¾ß ÇÕ´Ï´Ù.
¾Æ·¡´Â À̸§ÀÌ °°Àº INPUT űװ¡ ¿©·¯°³°¡ »ðÀԵǾî ÀÖ´Â html ±âº» ÆäÀÌÁöÀÔ´Ï´Ù. ´«¿©°Ü º¸½Ç ºÎºÐÀº INPUT ű×ÀÇ
À̸§(name)ÀÔ´Ï´Ù.
<html>
<head>
<title>www.webmadang.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body>
<form name="form" method="POST" action="addtext_test.php">
<input type="text" name="addText" size="20"><br>
<input type="text" name="addText" size="20"><br>
<input type="text" name="addText" size="20"><br>
<input type="text" name="addText" size="20"><br>
<input type="text" name="addText" size="20"><br>
<input type="submit" name="button" value="Àü ¼Û">
</form>
</body>
</html>
ASP,JSP¿¡¼´Â À§¿Í °°ÀÌ À̸§À» Á¤Çؼ ó¸®Çصµ µÇÁö¸¸ PHP¿¡¼´Â À§¿Í °°Àº °æ¿ì INPUT ű×ÀÇ À̸§À» ¹è¿ ÇüÅ·Π¸¸µé¾î Áà¾ß ÇÕ´Ï´Ù. ¾Æ·¡´Â INPUT ű×ÀÇ À̸§À» ¹è¿ ÇüÅ·Π¹Ù²Û ¿¹ÀÔ´Ï´Ù.
<!---- Àü¼ÛÇÒ ÆäÀÌÁö --->
<html>
<head>
<title>www.webmadang.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body>
<form name="form" method="POST" action="addtext_test.php">
<input type="text" name="addText[]" size="20"><br>
<input type="text" name="addText[]" size="20"><br>
<input type="text" name="addText[]" size="20"><br>
<input type="text" name="addText[]" size="20"><br>
<input type="text" name="addText[]" size="20"><br>
<input type="submit" name="button" value="Àü ¼Û">
</form>
</body>
</html>
Àü¼Û(submit) ¹öÆ°¿¡ ÀÇÇؼ Àü¼ÛÀÌ ÀÌ·ç¾îÁö¸é ¹Þ´Â PHP ÆäÀÌÁö¿¡¼ 󸮴 ¾ÆÁÖ °£´ÜÇÕ´Ï´Ù.
<?php
//¹Þ´Â ÆäÀÌÁö
$addText = $_REQUEST[addText];
$addText = implode(',',$addText);
echo $addText;
?>
³Ñ°ÜÁø °ªÀº ¹è¿·Î ÀúÀåµÇ°í implode ³ª join ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ ¹è¿¿¡ Ư¼ö¹®ÀÚ¸¦ »ðÀÔÇÏ¿© ÇÕÃÄÁÖ½Ã¸é µË´Ï´Ù.
³Ñ°ÜÁø °ªÀº ¾Æ·¡¿Í °°ÀÌ count ¶Ç´Â sizeof ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ °³º°ÀûÀ¸·Î È®ÀÎ ÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
<?php
//¹Þ´Â ÆäÀÌÁö
$addText = $_REQUEST[addText];
for($i=0;$i<count($addText);$i++)
{
echo $addText[$i]."<br>\n";
}
?>
PHP¿¡¼ À̸§ÀÌ µ¿ÀÏÇÑ Æûű×(Form Tag) ³»ÀÇ °ª(value) ó¸®ÇϱâÀÇ ÇÙ½ÉÀº µ¿ÀÏÇÑ À̸§À» °°´Â ű×ÀÇ °ªÀ» ¹è¿·Î Àâ¾Æ ÁÖ´Â °ÍÀÔ´Ï´Ù.
±×·³ ¹è¿Çü½ÄÀ¸·Î À̸§À» Àâ¾ÆÁØ INPUT ű×ÀÇ °ªÀ» »ç¿ëÀÚ°¡ ÀÔ·ÂÇÏÁö ¾ÊÀº °æ¿ì¿¡ ÀÚ¹Ù½ºÅ©¸³Æ®¿¡¼ 󸮴 ¾î¶»°Ô
ÇÒ±î¿ä?
document.form.elements["addText[]"][0].value;
INPUT ÅÂ±× Áß °¡Àå ù¹ø°´Â À§¿Í °°ÀÌ Á¢±ÙÇÒ ¼ö ÀÖ½À´Ï´Ù. ¾Æ´Ï¸é ¾Æ·¡ÀÇ ÀÚ¹Ù½ºÅ©¸³Æ® ¿¹Á¦¿Í °°ÀÌ Ã³¸®ÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
<html>
<head>
<title>www.webmadang.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<script language="javascript">
<!--
var oTbl;
//Row Ãß°¡
function insRow() {
oTbl = document.getElementById("addTable");
var oRow = oTbl.insertRow();
oRow.onmouseover=function(){oTbl.clickedRowIndex=this.rowIndex}; //clickedRowIndex - Ŭ¸¯ÇÑ RowÀÇ À§Ä¡¸¦ È®ÀÎ;
var oCell = oRow.insertCell();
//»ðÀ﵃ Form Tag
var frmTag = "<input type=text name=addText[] style=width:350px; height:20px;> ";
frmTag += "<input type=button value='»èÁ¦' onClick='removeRow()' style='cursor:hand'>";
oCell.innerHTML = frmTag;
}
//Row »èÁ¦
function removeRow() {
oTbl.deleteRow(oTbl.clickedRowIndex);
}
function frmCheck()
{
var frm = document.form;
for( var i = 0; i <= frm.elements.length - 1; i++ ){
if( frm.elements[i].name == "addText[]" )
{
if( !frm.elements[i].value ){
alert("ÅؽºÆ®¹Ú½º¿¡ °ªÀ» ÀÔ·ÂÇϼ¼¿ä!");
frm.elements[i].focus();
return;
}
}
}
}
//-->
</script>
</head>
<body>
<form name="form" method="post">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="left" bgcolor="#FFFFFF">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" bgcolor="#FFFFFF" height="25" align="left"><input name="addButton" type="button" style="cursor:hand" onClick="insRow()" value="Ãß°¡">
<font color="#FF0000">*</font>Ãß°¡¹öÆ°À» Ŭ¸¯ÇØ º¸¼¼¿ä.</td>
</tr>
<tr>
<td height="25">
<table id="addTable" width="400" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" border="0">
<tr>
<td><input type="text" name="addText[]" style="width:350px; height:20px;"></td>
<td align="left"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="10">
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="button" value="È®ÀÎ" onClick="frmCheck();">
</td>
</tr>
</table>
</form>
</body>
</html> |
|
̵̧ : 488 |
̵̧
¸ñ·Ï
|
|
|  |
|