rana aqib Javeed rana aqib Javeed - 2 months ago 8
PHP Question

Is it possible to post form data using an anchor tag (href)? codeigniter

<form id="my-form" method="POST">
<div class="row">
<div class="col-md-3">
<!-- /.form-group -->
<div class="form-group">
<label for="exampleInputEmail1">Employee<span class="text-danger"> *</span></label>
<select class="form-control" name="employee" id="employee">
<option value="">Select a Employee</option>
<?php
foreach ($result as $row) {
//var_dump($row);exit();
?>
<option value="<?= $row->ID;?>"> <?= $row->FNAME;?> </option>
<?php }?>
</select>

</div>
<!-- /.form-group -->
</div>

<div class="col-md-3">
<div class="form-group">
<label>Start Date<span class="text-danger"> *</span></label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type='date' class="form-control" name="sdate">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>End Date<span class="text-danger"> *</span></label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type='date' class="form-control" name="edate">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-2">
<div style="padding : 20px 50px">
<a class="btn btn-primary" style="float: right ;padding-left: 15px ;margin-right: 5px ;margin-top: 5px" id="view" >view</a>
</div>

</div>
</form>

<script>
$(document).on('change','#employee',function(){
var b = $(this).val();
$("#view").attr('href', '<?= base_url()?>admin/admin_view/'+b);
});
$("#view").on('click','#view',function(){
$("#my-form").submit();
});


My
href
is generated when I select any name from option. The problem is now that I want to post my data through the anchor tag. I don't know how to do this. I am using codeigniter 3. Hope this code allow you to understand my problem.

If anyone can help me I'll be thankful to him.

Answer Source

Follow this steps -

  1. When you change the employee, instead of assigning it to the href, assign it to form. Like this -

    $(document).on('change','#employee', function(){

        var b = $(this).val(); 
        $(form).attr('action',YOUR URL);         
    

    });

  2. In your tag set href="javascript:void(0)"

  3. Click on submit link.