title: Can I make a HTML input form field optional?
body: <p>Hi so I have a form in a HTML file. The input data is processed using Python and Flask using request.form. However, I would like some of the input fields to be optional. Currently I get the following error: </p>
  
  <pre><code> 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
  </code></pre>
  
  <p>I believe that this is due to some fields being empty.</p>
  
  <p>My form is designed in such a way that some fields only appear when a radio button is checked. The issues arises when the form is submitted and the radio button is not checked, as the form just treats them as empty.</p>
  
  <p>Here is my form code:</p>
  
  <pre><code>    &lt;form action = "makeBooking" method = "POST" &gt;
          Booking ID &lt;input type = "number" name = "bookingid" &gt;&lt;br&gt;
          Customer ID &lt;input type = "number" name = "customerid" &gt;&lt;br&gt;
          &lt;input type="radio" name="choice"&gt;
          &lt;label for="choice"&gt;Tick if new customer&lt;/label&gt;
          &lt;div class="reveal-if-active"&gt;
              First Name &lt;input type = "test" name = "firstname" VALUE="x" &gt;&lt;br&gt;
              Surname &lt;input type = "text" name = "surname"  VALUE="x"&gt;&lt;br&gt;
              Billing Address &lt;input type = "text" name = "address" VALUE="x" &gt;&lt;br&gt;
              Email &lt;input type = "text" name = "email"  VALUE="x"&gt;&lt;br&gt;
          &lt;/div&gt;
          Flight ID &lt;input type = "number" name = "flightid" &gt;&lt;br&gt;
          Number of Seats &lt;input type = "number" name = "numofseats" &gt;&lt;br&gt;
          &lt;input type = "submit" value = "Submit" &gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>The following Python code is where the error lies as they are submitted as empty if the radio button is unchecked.</p>
  
  <pre><code>bookingid = request.form['bookingid']
  customerid = request.form['customerid']
  flightid = request.form['flightid']
  numseats = request.form['numofseats']
  
  if request.form['choice']:
      firstname = request.form['firstname']
      surname = request.form['surname']
      address = request.form['address']
      email = request.form['email']
  
      #do some SQL insert statements with ALL the form data
  
  else: 
      #do some sql insert statements with the none hidden statements
  </code></pre>
  
  <p>Anyone have any ideas.</p>
  
  <p>Thanks.</p>
  
  <p>UPDATED: To show my code more clearly.</p>