<?php
session_start();
include '../assets/constant/config.php';

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}
?>
<?php include('include/sidebar.php'); ?>

<?php include('include/header.php'); ?>

<!--  connect author at mdkhairnar92@gmail.com  -->

<div class="page-content-wrapper ">

  <div class="container-fluid">

    <div class="row">
      <div class="col-sm-12">
        <div class="page-title-box">
          <div class="btn-group float-right">


          </div>
          <h4 class="page-title">Edit Custom Field</h4>
        </div>
      </div>
      <div class="clearfix"></div>
    </div>
    <!-- end page title end breadcrumb -->
    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">

            <div class="tab-content">

              <div class="tab-pane active p-3" id="home" role="tabpanel">
                <form name="myform" action="app/custom_field_crud.php" class="row" method="POST" enctype="multipart/form-data" onsubmit="return validation()" id="add_service">
<?php
                  $stmt = $conn->prepare("SELECT * FROM `custom_field` WHERE id=? ");
                  $stmt->execute([$_POST['id']]);
                  $record = $stmt->fetchAll();

                  foreach ($record as $key) { ?>
         
         <input class="form-control" type="hidden" name="id" value="<?php echo $key['id']; ?>">
                  
                       <div class="form-group col-md-3">
                              <label for="id_label_multiple">category<span class="text-danger">*</span> </label>
                              <select class="form-control postName" id="role" aria-label="Default select example" type="text" name="category" >
                              <option value="">Select </option>
                               <?php    
                                $sql1=$conn->prepare("select * from `category` where delete_status='0' ");
                                $sql1->execute();
                                $row1=$sql1->fetchAll();
                                //print_r($row);
                                //exit;
                                foreach ($row1 as $key1) {?>
                                <option value="<?php echo $key1['category_name'];?> ">
                                       <?php echo $key1['category_name'];?>
                                        </option>
                                    <?php } ?>
                              </select>
                           </div>
                  <div class="form-group col-md-6">
                    <label class="control-label">Field Name<span class="text-danger">*</span></label>
                    <input class="form-control" type="text" name="field_name" value="<?php echo $key['field_name'];?>" />
                  </div>

                   <div class="form-group col-md-6">
                    <label name="department" value="">Required Field<span class="text-danger">*</span></label>
                         <div>
                            
                         <input type="radio" name="field" value="yes" >
                                        YES
                         <input type="radio" name="field" value="no"> 
                                       NO

                        
                                        
                         </div>
                                </div> 
                          <div class="form-group col-md-6">
                    <label name="department" value="">Field Type<span class="text-danger">*</span></label>
                         <div>
                            
                         <input type="radio" name="field_type" value="1" >
                                         Text Field
                         <input type="radio" name="field_type" value="2"> 
                                      Date Field
                           <input type="radio" name="field_type" value="3"> 
                                         Number Field
                             <input type="radio" name="field_type" value="4"> 
                                        Decimal Field
                               <input type="radio" name="field_type" value="5"> 
                                        Radio Box
                                
                          </div>
                                </div> 

                 <div class="form-group col-md-12">

                    <button class="btn btn-primary" type="submit" name="update" onclick="addService()">Save</button>

                  </div>
                <?php }?>
                </form>
              </div>
              </div>

          </div>
        </div><!--end card-->
      </div><!--end col-->
    </div><!--end row-->
  </div> <!-- Page content Wrapper -->
</div> <!-- content -->

<?php include('include/footer.php'); ?>
<!--  Author Name: Mayuri K. 
 for any PHP, Codeignitor or Laravel website or software development contact me at mayuri.infospace@gmail.com  -->

<script type="text/javascript">
  function addService() {
    jQuery.validator.addMethod("alphanumeric", function(value, element) {
      return this.optional(element) || /^(?=.*[a-zA-Z])[a-zA-Z0-9\s!@#$%^&*()_-]+$/.test(value);
    }, "Please enter alphabet characters only");

    jQuery.validator.addMethod("lettersonly", function(value, element) {
      // Check if the value is empty
      if (value.trim() === "") {
        return false;
      }
      return /^[a-zA-Z\s]*$/.test(value);
    }, "Please enter alphabet characters only");
    $('#add_service').validate({
      rules: {
        category: {
          required: true,
           
        },

        field_name: {
          required: true
        },
        field: {
          required: true
        },
        field_type: {
          required: true
        }
      
      },
      messages: {
        category: {
          required: "Please enter a category"
         
        },

        field_type: {
             required: "Please enter a category"
           }
      }
    });
  };
</script>