아래의 소스에서 사진 등록을 필수로 하려면 어떻게 해야하나요.
본문
아래의 소스에서 사진 등록을 필수로 하려면 어떻게 해야하나요.
<script language="JavaScript">
var flen = 0;
function add_file(delete_code)
{
var upload_count = <?=(int)$board[bo_upload_count]?>;
if (upload_count && flen >= upload_count)
{
alert("이 게시판은 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
return;
}
var objTbl;
var objRow;
var objCell;
if (document.getElementById)
objTbl = document.getElementById("variableFiles");
else
objTbl = document.all["variableFiles"];
objRow = objTbl.insertRow(objTbl.rows.length);
objCell = objRow.insertCell(0);
objCell.innerHTML = "<input type='file' class=tx size=12 name='bf_file[]' title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능' style='color:<?=$board[bo_color_6]?>;background-color:<?=$board[bo_color_5]?>;border-color:<?=$board[bo_color_4]?>;border-width:1px;'><br>";
if (delete_code)
objCell.innerHTML += delete_code;
else
{
<? if ($is_file_content) { ?>
objCell.innerHTML += "<br><input type='text' size=12 class=tx name='bf_content[]' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.' style='width:100%; color:<?=$board[bo_color_6]?>;background-color:<?=$board[bo_color_5]?>;border-color:<?=$board[bo_color_4]?>;border-width:1px;'>";
<? } ?>
;
}
flen++;
}
<?=$file_script; //수정시에 필요한 스크립트?>
function del_file()
{
// file_length 이하로는 필드가 삭제되지 않아야 합니다.
var file_length = <?=(int)$file_length?>;
var objTbl = document.getElementById("variableFiles");
if (objTbl.rows.length - 1 > file_length)
{
objTbl.deleteRow(objTbl.rows.length - 1);
flen--;
}
}
</script>
답변 4
그누보드 기본체크소스를 활용하면
objCell.innerHTML = "<input type='file' class=tx size=12 name='bf_file[]' <==이부분에
objCell.innerHTML = "<input type='file' class=tx size=12 name='bf_file[]' required 로 수정해보세요
기본체크스크립트가 required 를 인식해서 체크합니다
선택이란님, 답변 대단히 감사합니다.
objCell.innerHTML = "<input type='file' class=tx size=12 name='bf_file[]' required 로 수정했습니다.
수정후 사진을 업로드하고 확인을 누르면, 다시 사진을 넣으라고 메시지가 나옵니다.
원본파일은 아래와 같습니다.
<script language="JavaScript">
var flen = 0;
function add_file(delete_code)
{
var upload_count = <?=(int)$board[bo_upload_count]?>;
if (upload_count && flen >= upload_count)
{
alert("이 게시판은 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
return;
}
var objTbl;
var objRow;
var objCell;
if (document.getElementById)
objTbl = document.getElementById("variableFiles");
else
objTbl = document.all["variableFiles"];
objRow = objTbl.insertRow(objTbl.rows.length);
objCell = objRow.insertCell(0);
objCell.innerHTML = "<input type='file' class=tx size=12 name='bf_file[]' required title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능' style='color:<?=$board[bo_color_6]?>;background-color:<?=$board[bo_color_5]?>;border-color:<?=$board[bo_color_4]?>;border-width:1px;'><br>";
if (delete_code)
objCell.innerHTML += delete_code;
else
{
<? if ($is_file_content) { ?>
objCell.innerHTML += "<br><input type='text' size=12 class=tx name='bf_content[]' required title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.' style='width:100%; color:<?=$board[bo_color_6]?>;background-color:<?=$board[bo_color_5]?>;border-color:<?=$board[bo_color_4]?>;border-width:1px;'>";
<? } ?>
;
}
flen++;
}
<?=$file_script; //수정시에 필요한 스크립트?>
function del_file()
{
// file_length 이하로는 필드가 삭제되지 않아야 합니다.
var file_length = <?=(int)$file_length?>;
var objTbl = document.getElementById("variableFiles");
if (objTbl.rows.length - 1 > file_length)
{
objTbl.deleteRow(objTbl.rows.length - 1);
flen--;
}
}
</script>
required 가 수정모드일땐 안나오게 하려면
required 를 <?=($w=='') ? "required":"";?> 로 교체해보세요
선택이란님, 답변 감사합니다.
적용을 했으나, 사진이 없는 상태에서 view페이지로 이동합니다.
답변을 작성하시기 전에 로그인 해주세요.