title: PHP Complex Syntax - Generating Proper Values in Forms
body: <p>I have an application that prompts users to fill out a form. When they hit submit, they are redirected to another page to verify their information. If they select edit (as opposed to confirming its accuracy), they are redirected to the original forms.</p>
  
  <p>In order to maintain the values across the pages, I am storing the initial form input in $_SESSION.</p>
  
  <p>The second "verification" page:</p>
  
  <pre><code>$_SESSION['formInput'] = $_POST;
  </code></pre>
  
  <p>If the user goes back to the original form, I am then looping back through this data and placing the user's input in the appropriate fields.</p>
  
  <pre><code>if($_SESSION['formInput']) {
  foreach($_SESSION['formInput'] as $key =&gt; $value) {
  
  ${$key} = $value;
  </code></pre>
  
  <p>Overall, this appears to work using something such as:</p>
  
  <pre><code>&lt;label&gt;First Name: &lt;/label&gt;&lt;input type='text' data-validation='[NAME]' id='primaryOneFirst' value='{$primaryOneFirst}' name='primaryOneFirst' data-validation-label='Field' /&gt;&lt;/div&gt;&lt;div class='formGroup colHalf'&gt;
  </code></pre>
  
  <p>However, there is a portion of the form that is dynamically generated based upon how many children the visitor has (indicated on another page). Overall, my approach for this has worked far as accessing the data and sending it through email; however, I am having a lot of trouble getting the values retained.</p>
  
  <p>For example, right know I have the following:</p>
  
  <pre><code>          $counter = 1;
            while($counter &lt;= $numberOf) {
  
            $html .= "&lt;div class='childField' id='child{$counter}'&gt;
  
      &lt;h3&gt;Child Data {$counter}&lt;/h3&gt;
  
      &lt;div class='row'&gt;&lt;div  class='formGroup colHalf'&gt;&lt;label&gt;Child Name: &lt;/label&gt;&lt;input type='text' data-validation
  
  ='[OPTIONAL, NAME]' data-validation-label='Field' name='childName{$counter}'  value='{$childName}$counter' /&gt;&lt;/div&gt;
  
  &lt;div class='formGroup colHalf'&gt;&lt;label&gt;Date of Birth:&lt;select name='childBirthmonth{$counter}'&gt;
                        &lt;option value=''&gt; &lt;/option&gt;
                           &lt;option value='01'&gt;January
                           &lt;/option&gt;
                           &lt;option value='02'&gt;February
                           &lt;/option&gt;
                           &lt;option value='03'&gt;March
                           &lt;/option&gt;
                           &lt;option value='04'&gt;April
                           &lt;/option&gt;
                           &lt;option value='05'&gt;May
                           &lt;/option&gt;
                           &lt;option value='06'&gt;June
                           &lt;/option&gt;
                           &lt;option value='07'&gt;July
                           &lt;/option&gt;
                           &lt;option value='08'&gt;August
                           &lt;/option&gt;
                           &lt;option value='09'&gt;September
                           &lt;/option&gt;
                           &lt;option value='10'&gt;October
                           &lt;/option&gt;
                           &lt;option value='11'&gt;November
                           &lt;/option&gt;
                           &lt;option value='12'&gt;December
                           &lt;/option&gt;
                           &lt;/select&gt;
  
  
                   &lt;select name='childBirthday{$counter}'&gt;"; for($i = 1; $i &lt;= 31; $i++) {
                           if($i &lt; 10) {
                           $i = "0" . $i;
                           }   $html .=  "&lt;option value='$i'&gt;$i&lt;/option&gt;";
                           }   $html .=  "&lt;/select&gt;
                           &lt;select name='childBirthyear{$counter}'&gt;";
  
                           for($i = 1900; $i &lt;= date("Y"); $i++) {
                            $html .=  "&lt;option value='$i'&gt;$i&lt;/option&gt;";
                           }   $html .=  "&lt;/select&gt;&lt;/div&gt;
  
                        &lt;/div&gt;
  
                        &lt;div class='row'&gt;&lt;div class='formGroup colHalf'&gt;&lt;label&gt; SSN: &lt;/label&gt;&lt;input type='text' placeholder='xxxxxxxxx' data-validation-message='Please enter a 9 digit SSN without dashes.' data-validation='[L==9, INTEGER, OPTIONAL]' value='$childSSN{$counter}' name='childSSN{$counter}' id='childSSN{$counter}' /&gt;&lt;/div&gt;&lt;div class='formGroup colHalf'&gt;&lt;label&gt;Gender: &lt;/label&gt;&lt;select value='childGender{$counter}' name='childGender{$counter}'&gt;&lt;option value='male'&gt;Male&lt;/option&gt;&lt;option value='female'&gt;Female&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;/div&gt;
  
                        &lt;div class='row'&gt;&lt;label&gt;Please Check All That Apply:&lt;/label&gt;&lt;/div&gt;&lt;ul class='checkBoxGroup' /&gt;&lt;li&gt;Handicapped: &lt;input type='checkbox' name='handicap{$counter}' value='handicap' /&gt;&lt;/li&gt;&lt;li&gt;Full-Time Student: &lt;input type='checkbox' name='student{$counter}' value='student' /&gt;&lt;/li&gt;&lt;li&gt;Step Child: &lt;input type='checkbox' name='step{$counter}' value='stepChild' /&gt;&lt;/li&gt;&lt;li&gt;Foster Child: &lt;input type='checkbox' name='foster{$counter}' value='foster' /&gt;&lt;/li&gt;&lt;li&gt;Different Address (than yours): &lt;input type='checkbox' name='diff{$counter}' value='differentAddress' /&gt;&lt;/li&gt;&lt;/ul&gt;
  
                        &lt;div class='childAddressBox'&gt;&lt;div class='row'&gt;&lt;div  id='childAddress{$counter}'&gt;&lt;div class='formGroup colHalf'&gt;&lt;label&gt;Address: &lt;/label&gt;&lt;input type='text'  value='$childAddress{$counter}' name='childAddress{$counter}' /&gt;&lt;/div&gt;&lt;div class='formGroup colHalf'&gt;&lt;label&gt;City: &lt;/label&gt;&lt;input type='text' size=20  value='$childCity{$counter}' name='childCity{$counter}' /&gt;&lt;/div&gt;&lt;/div&gt;
  
                         &lt;div class='row'&gt;&lt;div  class='formGroup colHalf'&gt;&lt;label&gt;State: &lt;/label&gt;&lt;input type='text' size=2 value='$childState{$counter}' name='childState{$counter}'/&gt;&lt;/div&gt;&lt;div class='formGroup colHalf'&gt;&lt;label&gt;Zip&lt;/label&gt;&lt;input type='text' size=5 value='$childZip{$counter}' name='childZip{$counter}' /&gt;&lt;/div&gt;&lt;/div&gt;
                         &lt;/div&gt;
                         &lt;/div&gt;&lt;/div&gt;";
                        $counter++;
        }
        echo $html;      
  }
  </code></pre>
  
  <p>I have tried multiple approaches, but instead of getting the desired output (the child's name, SSN, or address), I am just getting the value of $counter (1). Instead of something like <code>value='{$childName}$counter'</code> or  <code>value='$childSSN{$counter}</code>' I need it to literally translate to somehing such as <code>value='{$childName1}'</code> or <code>value='{$childSSN1}</code> , just like the other portions of the form. How can I accomplish this?</p>
  
  <p>Thanks so much!</p>