단일 폼안에 다중 Submit 사용하기
author 관리자 date 2003-11-17 hit 175 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  
31  PHP7 클래스 선언 방법  2021-11-03 397
30  PHP7 배열 선언 코드  2021-11-03 629
29  PHP 코드를 최적화하는 40가지 팁 (번역)  2009-12-23 590
28  if , else 조건문 코드 줄이기 (?:)  2009-12-23 438
27  간단한 이메일 보내기 클래스  2008-03-05 558
26  PHP 로 TTF 파일을 웹폰트로 만들기  2006-05-28 565
25  업로드 이미지 사이즈 처리  2006-05-23 481
24  glob -- Find pathnames matching a pattern  2006-05-18 342
23  Thumbnail Image (GD 처리)  2006-05-15 397
22  첨부 이미지(스샷) 사이즈 조정  2006-05-15 276
21  PHP Fuction 검색 창 소스  2006-04-11 359
20  이미지 파일의 가로, 세로 픽셀 알아내기  2006-04-11 319
19  테스트용 변수 출력 소스  2006-04-06 306
18  SMS 발송 - 명단 입력 스크립트  2005-09-16 293
17  리눅스 apache, php 에서 mssql connecting 하기  2005-06-07 494
16  php를 이용하여 서버 백업 프로그램 짜기  2004-05-04 460
15  베이비 헤로스 이벤트 소스  2004-04-28 277
14  세션 생성..  2004-04-21 343
13  제로보드 view.php 분석  2004-04-07 305
12  다중 게시판 검색  2004-03-25 1322
1 2