Ahmed Badreldin Amado
Ahmed Badreldin Amado

Reputation: 41

The URL is not like what I want

When I press on submit button on form in CodeIgniter, if I am at XController/loadX and my action is YController/loadY, the URL becomes like Xcontroller/loadX/Ycontriller/loadY, and I want it to be just YController/loadY.

  <form name="SpecAccept"method="post"action="SpecialistController/loadDoctor">
    <div class="form-group col-sm-12" id="myDiv" align="right">
        <span><label>الولاية</label></span>
        <select style="font-size:12px"  class="form-control" id="state_name" onchange="change(this)">
            <option>--- اختر الولاية ---</option>
            <?php
                foreach($states as $Object){
                echo '<option value="'.$Object->StateID.'">'.$Object->StateName.'</option>';
                }
            ?>

        </select>   
    </div>
    <div class="form-group col-sm-6" id="myDiv" align="right">
        <span><label>المهنة</label></span>
        <select style="font-size:12px" class="form-control" id="career_name" >
            <option>--- اختر المهنة ---</option>
            <?php
                foreach($careers as $Object){
                echo '<option value="'.$Object->CareerID.'">'.$Object->CareerName.'</option>';
                }
            ?>

        </select>   
    </div>
    <div class="form-group col-sm-6" id="myDiv" align="right">
        <span><label>المستشفى</label></span>
        <select style="font-size:12px"  class="form-control" id="hospitals" name="Hospitals" >
            <option value="0" isSelected>اختر الولاية اولاً</option>
        </select>
    </div>                                          
   <div class="form-group col-sm-12">
    <button type="sumbit">عرض</button>
    </div>
</form>

what is the problem and how to fix it?

Upvotes: 1

Views: 70

Answers (2)

Mary
Mary

Reputation: 197

try to use javascript

<button type="button" onclick="Function_name();" >عرض</button>

then in a javascript you can do that

<script>
function Function_name(){
alert ('I AM HERE');
document.SpecAccept.submit();
}
   </script>

that alert is to see if the button works and enter in the function.

if that not work try to change the type of form like this

<?php
    $attributes = array(
                    'id' => 'SpecAccept',
                    'name' => 'SpecAccept',
                    'autocomplete' => 'off',
                    'enctype' => 'multipart/form-data',
                );
               echo form_open_multipart('SpecialistController/loadDoctor'); // this is the open <form>
?> 

then for closed it replaces </form> tag for

<?php echo form_close();?>

Upvotes: 1

Geordy James
Geordy James

Reputation: 2398

First, you need to define base URL in config.php file like this

$config['base_url'] = 'http://localhost/projectfoldername/';

Now in form action URL

<form name="SpecAccept"method="post"action="<?php echo base_url('SpecialistController/loadDoctor'); ?> ">

Upvotes: 0

Related Questions