| 제목 | p126 글쓰기 질문드려요 | |||
|---|---|---|---|---|
| 글쓴이 | 용인몽 | 작성시각 | 2014/08/27 01:14:05 | |
|
|
||||
[write_v.php]
<article id="board_area">
<form id="write_action" action="" method="post">
<fieldset>
<legend>게시물 쓰기</legend>
<div class="control-group">
<label class="control-label" for="input01">제목</label>
<div class="controls">
<input type="text" class="input-xlarge" id="input01" name="subject" >
<p class="help-block">게시물의 제목을 써주세요.</p>
</div>
<label class="control-label" for="input02">내용</label>
<div class="controls">
<textarea class="input-xlarge" id="input02" name="contents" rows="5"></textarea>
<p class="help-block">게시물의 내용을 써주세요.</p>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" id="write_btn">작성</button>
<button class="btn" onclick="document.location.reload()">취소</button>
</div>
</div>
</fieldset>
</form>
</article>
[board.php]
/**
* 게시물 쓰기
*/
function write()
{
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
if($_POST)
{
//경고창 헬퍼 로딩
$this->load->helper('alert');
//주소 중에서 page 세그먼트가 있는지 검사하기 위해 주소를 배열로 변환
$uri_array = $this->segment_explode($this->uri->uri_string());
if(in_array('page' , $uri_array))
{
$pages = urldecode($this->url_explode($uri_array , 'page'));
}
else
{
$pages = 1;
}
if( !$this->input->post('subject' , TRUE) && !$this->input->post('contents' , TRUE))
{
//글 내용이 없을 경우, 프로그램단에서 한 번 더 체크
alert('비정상적인 접근입니다.' , '/bbs/board/lists/'.$this->uri->segment(3).'/page/'.$pages);
exit;
}
$write_date = array(
'table' => $this->uri->segment(3),
'subject' => $this->input->post('subject' , TRUE),
'contents' => $this->input->post('contents' , TRUE),
);
$result = $this->board_m->insert_board($write_data);
if ( $result )
{
//글 작성 성공시 게시판 목록으로
alert('입력되었습니다.', '/bbs/board/lists/'.$this->uri->segment(3).'/page/'.$pages);
exit;
}
else
{
//글 실패시 게시판 목록으로
alert('다시 입력해 주세요.', '/bbs/board/lists/'.$this->uri->segment(3).'/page/'.$pages);
exit;
}
}
else
{
$this->load->view('board/write_v');
}
}
|
||||
| 다음글 | 초보자 문의 입니다. 4과 게시판 테이블 만들기 관련 (1) | |||
| 이전글 | list_v페이지가 제대로 출력되지 않는 문제에 대한 ... (1) | |||
|
변종원(웅파)
/
2014/08/27 10:24:27 /
추천
0
|
|
널곰
/
2015/05/17 02:17:45 /
추천
0
위에 폼 태그를 폼헬퍼를 로드하여 form_open()을 사용해야 합니다.
저도 겪어봐서 아는데
<form id="write_action" action="" method="post" />
// 위의 폼 태그를 아래 php 코드로 변환
<?php
$attributes = array('class'=>'form-horizontal', 'id'=>'write_action');
echo form_open(' ', $attributes);
?>
// 그러면, csrf 토큰이 input hidden 값으로 자동 생성됨
// PS. 닫는 폼태그도 그냥 나두기 모하면 아래 코드로 바꿈..
</ form>
<?php echo form_close(); ?>
|
http://cikorea.net/qna/view/6602/page/1 참고하세요.