제목 단일 폼안에 다중 Submit 사용하기
등록자 관리자 등록일시 2003-11-17 조회수 119 HIT
단일상품 구매도 가능하고 다중 상품도 구매가 가능한 방법이 있어 소개합니다.

이미지 Submit 버튼을 이용하시면 여러개의 Submit 버튼이 있어도 어느것이 눌러졌는지 PHP 에서 알 수 있습니다.

Submit 이름이 sub[0]~sub[9]라고 한다면 sub[0]_x 이렇게 확인하시면 될것 같습니다.

/* index.php */
<?
$pro_num = array(12,13,14,15,16,17,18,19,20,21);
?>
<html>
<head>
<title>무제 문서</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="process.php">
<table width="400" border="0" cellspacing="0" cellpadding="2">
<?
$pro_cnt = count($pro_num);
for($i=0; $i<$pro_cnt; $i++) {
?>
<tr>
<td><?echo$i?></td>
<td>상품설명<?echo$i?></td>
<td width="120">
<input type="hidden" name="all_product[<?echo$i?>]" value="<?echo$pro_num[$i]?>">
<input type="checkbox" name="product[<?echo$i?>]" value="<?echo$pro_num[$i]?>">
<input type="image" border="0" name="sub[<?echo$i?>]" src="abc.gif" width="80" height="24">
</td>
</tr>
<? } ?>
</table>
</form>
</body>
</html>

/* process.php */
<?
$select_product = array();

for($i=0; $i<10; $i++) {
if($product[$i] != Null) {
$select_product[] = $product[$i];
}
}

for($i=0; $i<10; $i++) {
if($sub[$i] != Null) {
$select_submit = $all_product[$i];
}
}

if(!in_array($select_submit, $select_product) ) {
$select_product[] = $select_submit;
}

$select_cnt = count($select_product);

for($i=0; $i<$select_cnt; $i++) {
echo "구매 상품 : $select_product[$i]<br>";
}
?>
목록보기

        X  
11  PHP + JAVASCRIPT 로 해상도 체크  2003-11-17 153
10  MySQL 을 이용한 사용자 인증  2003-11-17 156
9  여러개의 난수를 중복없이 발생시키는 함수  2003-11-17 149
8  가로, 세로 비율 틀려지지 않고 크기에 맞는 썸네일 만들기  2003-11-17 117
 단일 폼안에 다중 Submit 사용하기  2003-11-17 119
6  업로드 파일 처리 루틴  2003-11-17 120
5  암호화 함수 crypt() 사용예제  2003-11-17 119
4  동일문서내의 php 배열변수를 자바스크립트에서 사용하기  2003-11-17 132
3  세션을 이용한 현재 접속자 체크 함수  2003-11-17 125
2  Timestamp 값을 날짜로 변환하기  2003-11-17 125
1  아파치 사용자인증 (User Authentication)  2003-11-17 128
1 2