title: How best to pre populate a radio button selection using php?
body: <p>I'm working on an application form.</p>
  
  <p>It is to be pre populated with an individuals details, we already have their details. Basically we send them a link to their form, already populated with their details, we then simply ask them to check the form and hit submit if all info is correct.</p>
  
  <p>I have the following to pre populate simple text boxes:</p>
  
  <pre><code>&lt;input type="text" name="forename" id="input-forename" value="&lt;?php echo htmlspecialchars(@$_REQUEST['forename']);?&gt;"/&gt;    
  
  &lt;input type="text" name="birthdate" id="input-birthdate" value="&lt;?php echo htmlspecialchars(@$_REQUEST['date_of_birth']);?&gt;" /&gt;
  </code></pre>
  
  <p>etc.</p>
  
  <p>Everything works great with this.</p>
  
  <p>I'm having difficulty with the radio buttons though.</p>
  
  <p>This selection for example:</p>
  
  <pre><code>&lt;label for="input-title-mr"&gt;Mr: &lt;input type="radio" name="title" id="input-title-mr" value="Mr" /&gt;&lt;/label&gt;
  &lt;label for="input-title-mrs"&gt;Mrs: &lt;input type="radio" name="title" id="input-title-mrs" value="Mrs" /&gt;&lt;/label&gt;
  &lt;label for="input-title-miss"&gt;Miss: &lt;input type="radio" name="title" id="input-title-miss" value="Miss" /&gt;&lt;/label&gt;
  &lt;label for="input-title-ms"&gt;Ms: &lt;input type="radio" name="title" id="input-title-ms" value="Ms" /&gt;&lt;/label&gt;
  </code></pre>
  
  <p>Would there be a good way of perhaps using the checked="" attribute and a php if statement to pre check the correct radio button?</p>
  
  <p>Perhaps something along the lines of this:</p>
  
  <pre><code>&lt;label for="input-title-mr"&gt;Mr: &lt;input type="radio" name="title" id="input-title-mr" value="Mr" checked="&lt;?php if ( @$_REQUEST['forename'] == 'Mr' ) { echo 'checked'; }?&gt;" /&gt;&lt;/label&gt;
  </code></pre>
  
  <p>I hope this makes sense and any help or advice would be greatly appreciated :)</p>