나는 다음과 같은 형태를 따른다 :숨기기 및 표시 필드
<fieldset id="upload-form">
<ul>
<li>
<div class="radio-list clearfix">
<ul>
<li><label for="r1"><input type="radio" name="category" id="r1" value="34" checked="checked" /> Discussion</label></li>
<li><label for="r2"><input type="radio" name="category" id="r2" value="35" /> Question</label></li>
<li><label for="r3"><input type="radio" name="category" id="r3" value="36" /> Code</label></li>
<li><label for="r4"><input type="radio" name="category" id="r4" value="37" /> Link</label></li>
</ul>
</div>
</li>
<li>
<label for="title">Title <span>required & make it descriptive</span></label>
<input id="title" type="text" name="title" />
</li>
<li>
<label for="url">URL <span>don't forget the http://</span></label>
<input id="url" type="text" name="url" placeholder="http://" />
</li>
<li>
<label for="topic">Discussion topic</label>
<textarea id="topic" name="topic"></textarea>
</li>
<li>
<label for="question">Your question <span>help text</span></label>
<textarea id="question" name="question"></textarea>
</li>
<li>
<label for="description">Description <span>help text</span></label>
<textarea id="description" name="description"></textarea>
</li>
<li>
<label for="code">Code</label>
<textarea id="code" name="code"></textarea>
</li>
<li>
<label for="tags">Tags <span>separate multiple tags with commas</span></label>
<textarea id="tags" name="tags"></textarea>
</li>
<li>
<label class="public" for="public"><input id="public" type="checkbox" name="public" /> Make this post public? <span>(non-members will be able to view this post)</span></label>
</li>
<li class="clearfix">
<input class="submit" type="submit" name="" value="Post" />
<input class="cancel" type="button" value="Cancel" onclick="window.location.href='<?php bloginfo('url'); ?>/posts'" />
</li>
</ul>
</fieldset>
무엇 일어날 사용자가 그것을 숨길 양식의 상단에있는 라디오 버튼 중 하나를 선택하거나 특정 필드를 표시 할 때입니다 해당 카테고리와 관련이 있습니다. 예를 들어 링크 카테고리의 경우 사용되는 필드는 제목, URL 및 설명입니다.
jQuery를 사용하여 필드를 숨기거나 표시하려고하지만 서버 측 코드는 어떻게됩니까? 사용자가 필드 채우기를 시작한 후 카테고리를 변경하기로 결정한 것처럼 잘못된 필드를 게시하는 것을 원하지 않습니다. 어떻게해야합니까?
저는 WordPress를 사용하고 있으며 양식은 PHP로 코딩되어 있습니다. 다음은 양식에서 게시 정보를 수집하여 데이터베이스에 저장하는 방법에 대한 몇 가지 샘플 코드입니다. 감사.
<?php
/* Template Name: New Post */
if(isset($_POST['new_post']) == '1')
{
$post_title = $_POST['post_title'];
$post_category = $_POST['cat'];
$post_content = $_POST['post_content'];
$post_timelimit = $_POST['timelimit'];
$new_post = array(
'ID' => '',
'post_author' => $user->ID,
'post_content' => $post_content,
'post_title' => $post_title,
'post_status' => 'publish',
'tax_input' => array('timelimit' => $post_timelimit)
);
$post_id = wp_insert_post($new_post);
// tags have to be added seperate? :/
wp_set_post_tags($post_id, $_POST['post_tags']);
// This will redirect you to the newly created post
$post = get_post($post_id);
wp_redirect($post->guid);
}
get_header();
?>
해당 양식에 대해 PHP를 업데이트해야하며 입력을 검토하지 않아야합니다. $ _POST는 양식 입력의 이름과 일치해야합니다. – Jacob
샘플 코드입니다. 실제 폼 코드는 아닙니다. – Cameron