title: Hide and show fields based on radio choice
body: <p>I have the following form:</p>
  
  <pre><code>&lt;fieldset id="upload-form"&gt;                     
                          &lt;ul&gt;
                              &lt;li&gt;
                                  &lt;div class="radio-list clearfix"&gt;
                                  &lt;ul&gt;
                                      &lt;li&gt;&lt;label for="r1"&gt;&lt;input type="radio" name="category" id="r1" value="34" checked="checked" /&gt; Discussion&lt;/label&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;label for="r2"&gt;&lt;input type="radio" name="category" id="r2" value="35" /&gt; Question&lt;/label&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;label for="r3"&gt;&lt;input type="radio" name="category" id="r3" value="36" /&gt; Code&lt;/label&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;label for="r4"&gt;&lt;input type="radio" name="category" id="r4" value="37" /&gt; Link&lt;/label&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                                  &lt;/div&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="title"&gt;Title &lt;span&gt;required &amp;amp; make it descriptive&lt;/span&gt;&lt;/label&gt;
                                  &lt;input id="title" type="text" name="title" /&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="url"&gt;URL &lt;span&gt;don't forget the http://&lt;/span&gt;&lt;/label&gt;
                                  &lt;input id="url" type="text" name="url" placeholder="http://" /&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="topic"&gt;Discussion topic&lt;/label&gt;
                                  &lt;textarea id="topic" name="topic"&gt;&lt;/textarea&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="question"&gt;Your question &lt;span&gt;help text&lt;/span&gt;&lt;/label&gt;
                                  &lt;textarea id="question" name="question"&gt;&lt;/textarea&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="description"&gt;Description &lt;span&gt;help text&lt;/span&gt;&lt;/label&gt;
                                  &lt;textarea id="description" name="description"&gt;&lt;/textarea&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="code"&gt;Code&lt;/label&gt;
                                  &lt;textarea id="code" name="code"&gt;&lt;/textarea&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label for="tags"&gt;Tags &lt;span&gt;separate multiple tags with commas&lt;/span&gt;&lt;/label&gt;
                                  &lt;textarea id="tags" name="tags"&gt;&lt;/textarea&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;label class="public" for="public"&gt;&lt;input id="public" type="checkbox" name="public" /&gt; Make this post public? &lt;span&gt;( non-members will be able to view this post )&lt;/span&gt;&lt;/label&gt;
                              &lt;/li&gt;
                              &lt;li class="clearfix"&gt;
                                  &lt;input class="submit" type="submit" name="" value="Post" /&gt;
                                  &lt;input class="cancel" type="button" value="Cancel" onclick="window.location.href='&lt;?php bloginfo('url'); ?&gt;/posts'" /&gt;
                              &lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/fieldset&gt;
  </code></pre>
  
  <p>What will happen is when a user chooses one of the radio buttons at the top of the form it will hide or show certain fields that are relevant to that category. So for example for the Link category the only fields used will be Title, URL, and Description.</p>
  
  <p>I plan to use jQuery to hide and show the fields, but what about the server-side code? As if a user starts filling in fields but then decides to change the category I don't want them posting the wrong fields etc. How would I accomplish this?</p>
  
  <p>I'm using WordPress and the form is coded using PHP. Here is some sample code of how the form will grab the post information and save it to the database. Thanks.</p>
  
  <pre><code>&lt;?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' =&gt; '',
                'post_author' =&gt; $user-&gt;ID, 
                'post_content' =&gt; $post_content, 
                'post_title' =&gt; $post_title,
                'post_status' =&gt; 'publish',
                'tax_input' =&gt; array('timelimit' =&gt; $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-&gt;guid);
      }
  
      get_header();
  
  ?&gt;
  </code></pre>