title: How to process two forms on a page in PHP
body: <p>When processing two forms on a page how do I prevent <code>Undefined Index</code> for a variable that has not been submitted?</p>
  <p>I have a page with two forms and I am trying to send one of the forms to the server, but I keep getting variables from the other form as an undefined index.</p>
  <pre><code>&lt;form id=&quot;dassets&quot; class=&quot;d-none&quot; action=&quot;process.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;div&gt;
      &lt;label class=&quot;medium my-2&quot; for=&quot;assetType&quot;&gt;Type&lt;/label&gt;
      &lt;input class=&quot;form-control my-2&quot; name=&quot;coinName&quot; id=&quot;assetType&quot; type=&quot;text&quot; placeholder=&quot;Card Selected&quot; /readonly&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;col px-0&quot;&gt;
      &lt;!-- Get current BTC value in dollars --&gt;
      &lt;div id=&quot;dataBTC&quot; class=&quot;text-primary&quot;&gt;&lt;/div&gt;
  
      &lt;label class=&quot;medium my-2&quot;&gt;Coin value&lt;/label&gt;
      &lt;div class=&quot;input-group input-group-sm mb-3&quot;&gt;
        &lt;div class=&quot;input-group-prepend&quot;&gt;
          &lt;span class=&quot;input-group-text&quot; id=&quot;coin-value&quot;&gt;BTC&lt;/span&gt;
        &lt;/div&gt;
        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;quantity&quot; aria-label=&quot;BTC&quot; aria-describedby=&quot;coin-value&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;div class=&quot;col px-0&quot;&gt;
        &lt;label for=&quot;file01&quot; class=&quot;my-2&quot;&gt;Please upload a very clear photo of the payment receipt/gift card where necessary&lt;/label&gt;
  
        &lt;div class=&quot;form-group mt-4&quot;&gt;
          &lt;label for=&quot;file01&quot;&gt;Upload a file&lt;/label&gt;
          &lt;input type=&quot;file&quot; class=&quot;form-control-file&quot; id=&quot;file01&quot;&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;BTC&quot;&gt;
      &lt;input type=&quot;submit&quot; class=&quot;btn btn-success btn-rounded px-3 mt-3&quot; value=&quot;Trade&quot; name=&quot;submit&quot;/&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;!-- Card trade --&gt;
  &lt;div class=&quot;col-xl-7 card-body d-none&quot; id=&quot;dock&quot;&gt;
  </code></pre>
  <p>Here is the second form; I added a hidden field to distinguish them:</p>
  <pre><code>&lt;form id=&quot;amazonForm&quot; class=&quot;d-none&quot; action=&quot;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;div&gt;
      &lt;label for=&quot;cardType&quot;&gt;Type&lt;/label&gt;
      &lt;input class=&quot;form-control&quot; id=&quot;typeAmazon&quot; type=&quot;text&quot; placeholder=&quot;Card Selected&quot; name=&quot;ca2rdType&quot; readonly/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col px-0&quot;&gt;
      &lt;label for=&quot;ctry&quot; class=&quot;my-2&quot;&gt;Country&lt;/label&gt;
      &lt;select id=&quot;ctryAmazon&quot; class=&quot;form-control&quot; name=&quot;country&quot;&gt;
        &lt;option selected&gt;USD&lt;/option&gt;
        &lt;option&gt;EUR&lt;/option&gt;
        &lt;option&gt;CAD&lt;/option&gt;
        &lt;option&gt;GDP&lt;/option&gt;
        &lt;option&gt;CHF&lt;/option&gt;
        &lt;option&gt;AUD&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col px-0&quot;&gt;
      &lt;label for=&quot;country&quot; class=&quot;my-3&quot;&gt;Select Gift Card Type&lt;/label&gt;
  
      &lt;!--Amazon Gift Cards --&gt;
      &lt;div id=&quot;amazonUsa&quot; class=&quot;d-none&quot;&gt;
  
        &lt;!-- Cash Receipt --&gt;
        &lt;div class=&quot;custom-control custom-checkbox &quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;amazonCash&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;amazonCash&quot;&gt;Cash Receipt&lt;/label&gt;
        &lt;/div&gt;
  
        &lt;!-- Debit Receipt --&gt;
        &lt;div class=&quot;custom-control custom-checkbox&quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;amazonDebit&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;amazonDebit&quot;&gt;Debit Receipt&lt;/label&gt;
        &lt;/div&gt;
  
        &lt;!-- No Receipt --&gt;
        &lt;div class=&quot;custom-control custom-checkbox&quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;noReceipt&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;noReceipt&quot;&gt;No Receipt&lt;/label&gt;
        &lt;/div&gt;
  
        &lt;!-- Ecode --&gt;
        &lt;div class=&quot;custom-control custom-checkbox&quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;eCode&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;eCode&quot;&gt;Ecode&lt;/label&gt;
        &lt;/div&gt;
  
        &lt;!-- Physical --&gt;
        &lt;div class=&quot;custom-control custom-checkbox&quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;physical&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;physical&quot;&gt;Physical&lt;/label&gt;
        &lt;/div&gt;
  
        &lt;!-- Large card --&gt;
        &lt;div class=&quot;custom-control custom-checkbox&quot;&gt;
          &lt;input type=&quot;checkbox&quot; class=&quot;custom-control-input&quot; id=&quot;largecard&quot;&gt;
          &lt;label class=&quot;custom-control-label&quot; for=&quot;largecard&quot;&gt;Large Card&lt;/label&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group&quot;&gt;
        &lt;div class=&quot;col d-md-flex justify-content-between px-0&quot;&gt;
          &lt;div&gt;
            &lt;label for=&quot;amount&quot; class=&quot;my-3&quot;&gt;Input card value amount&lt;/label&gt;
            &lt;input class=&quot;form-control&quot; id=&quot;amount&quot; type=&quot;number&quot; placeholder=&quot;Enter an amount&quot;/&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;label for=&quot;equivalent&quot; class=&quot;my-3&quot;&gt;Equivalent in Naira&lt;/label&gt;
            &lt;input class=&quot;form-control text-success&quot; id=&quot;cashout&quot; type=&quot;text&quot; placeholder=&quot;Cashout in Naira&quot; readonly/&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;col px-0&quot;&gt;
        &lt;label for=&quot;file02&quot; class=&quot;my-2&quot;&gt;Please upload a very clear photo of the payment receipt/giftcard&lt;/label&gt;
  
        &lt;div class=&quot;form-group mt-4&quot;&gt;
          &lt;label for=&quot;file01&quot;&gt;Upload a file&lt;/label&gt;
          &lt;input type=&quot;file&quot; class=&quot;form-control-file&quot; id=&quot;file02&quot;&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;GTC&quot;&gt;
      &lt;input type=&quot;submit&quot; class=&quot;btn btn-success btn-rounded px-3 mt-3&quot; value=&quot;Trade&quot; name=&quot;submit_2&quot;/&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>