Build Form on Dashboard

After did many trials and errors, finally I found the answer.

Just in case anyone wondering how this working, I put the full code right here :

/* == THEME OPTIONS == */

add_action("admin_menu", "setup_theme_admin_menus");

function setup_theme_admin_menus() {
    add_submenu_page('themes.php', 
        'Generate Coupons', 'Generate Coupons', 'manage_options', 
        'generate-coupons-elements', 'theme_generate_coupons_settings'); 
}

function theme_generate_coupons_settings() {
?>
  <div class="wrap">
    <?php screen_icon('themes'); ?> <h2>Generate Coupons</h2>

    <form method="POST" action="">
      <table class="form-table">
        <tr valign="top">
          <th scope="row">
            <label for="coupon">
              Number of coupons:
            </label> 
          </th>
          <td>
            <input type="text" name="coupon" size="25" />
          </td>
        </tr>
        <tr valign="top">
          <th scope="row">
            <label for="discount">
              Amount of discount:
            </label> 
          </th>
          <td>
            <input type="text" name="discount" size="25" />
          </td>
        </tr>
      </table>
      <p>
        <input type="hidden" name="update_settings" value="Y" />
        <input type="submit" value="Generate" class="button-primary"/>
      </p>
    </form>
  </div>
<?php
  if (isset($_POST["update_settings"])) {
    $coupon = esc_attr($_POST["coupon"]); 
    $discount = esc_attr($_POST["discount"]); 
    $coupon_code="UNIQUECODES"; // Code
    $amount = $discount; // Amount
    $discount_type="fixed_cart"; // Type: fixed_cart, percent, fixed_product, percent_product

    $coupon = array(
      'post_title' => $coupon_code,
      'post_content' => '',
      'post_status' => 'publish',
      'post_author' => 1,
      'post_type'   => 'shop_coupon'
    );

    $new_coupon_id = wp_insert_post( $coupon );

    // Add meta
    update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
    update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
    update_post_meta( $new_coupon_id, 'individual_use', 'no' );
    update_post_meta( $new_coupon_id, 'product_ids', '' );
    update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
    update_post_meta( $new_coupon_id, 'usage_limit', '1' );
    update_post_meta( $new_coupon_id, 'usage_limit_per_user', '1' );
    update_post_meta( $new_coupon_id, 'expiry_date', '' );
    update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
    update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
    ?>
      <div id="message" class="updated">Coupon generated!</div>
    <?php
  }
}

/* == END OF THEME OPTIONS == */