0

I'd like some help please. I'm having this link

<?php echo anchor('contact#apply', 'Apply for Job'); ?>

in my Careers page /view, which redirects to the Contact, where I have this dropdown menu in my form

$reasons = array(
            'request-feedback'  => 'I'd like more information please',
            'request-a-demo'=> 'I want a demo of your services', 
            'work-with-us'  => 'I am interested in working for youy company', // * this is the option I'm interested in
);
<?php echo form_label('Reason for getting in touch with us', 'reason'); ?>
<?php echo form_dropdown('reason', $reasons, null, 'class="form-control"'); ?> // * when user applies for job should have the 3rd option pre selected instead of null
<?php echo form_error('topic'); ?>

What I'd like to do is when a user clicks on that link to redirect him to the contact form and have the work-with-us option pre selected, but only in this case, in any other case the default should be the first one.

How can I do this ?

Note: both Careers and Contact pages have this structure

careers/index // i.e. controller/method
contact/index

so basicaly there are two different controllers

Rohit Gaikwad
  • 817
  • 2
  • 8
  • 24
ltdev
  • 4,037
  • 20
  • 69
  • 129
  • possible duplicate of [CodeIgniter select\_value in form\_dropdown](http://stackoverflow.com/questions/14445982/codeigniter-select-value-in-form-dropdown) – Peter Uhnak Sep 10 '15 at 08:58
  • @Peter I'm basicaly asking how to pre select a value only if this link is clicked, not in all cases – ltdev Sep 10 '15 at 09:06

2 Answers2

1

You can do this in this way. In the url, there should be an 'id' to identify that it coming from 'contact/apply' link.You can do it in this way

<?php echo anchor('contact/apply?id=contact', 'Apply for Job'); ?>

in your 'apply' method in 'contact' controller, it can check the id

public function apply(){
   if(isset($_GET['id'])){
     $id=$_GET['id'];
     if($id=='contact'){
      $selected='work-with-us';
     }
     else{
       $selected='request-feedback';
     }
 }
 else{
   $selected='request-feedback';
 }

  //the data send to view page
  $data['selected_val']=$selected;
  $this->load->view('view_page', $data);
}

then in your 'view_page' in the relevant drop down, it can set the selected value

<?php echo form_dropdown('reason', $reasons, $selected_val, 'class="form-control"'); ?>

Hope this will help.

Janaka
  • 398
  • 5
  • 16
  • Yeap! Its working! one additional thing.. When I was selecting the `work-with-us` option, I also display an input field for uploading a CV, I did this with jquery `on.change` event .. How can I display this field in this case too ? – ltdev Sep 10 '15 at 14:35
0

Way to the second case..

<?php if($selected_val!='work-with-us'){ ?>
   <script>
     $(document).ready(function(){
         $("#depend_on_select").hide();
     });
   </script>
<?php } ?>

<div id="depend_on_select">
   <input type="file" name="cv">
</div>

In here the div that contain cv will show only $selected_val='work-with-us'.

Janaka
  • 398
  • 5
  • 16