Welcome Guest, Not a member yet? Register   Sign In
Codeigniter set_value not working
#1
Thumbs Up 

I'm querying the DB and sending sending a $data array from my controller to my view, where I'm using CI's form helper with set_value(field_name, default) but the data is not being loaded.
This is what I'm currently doing in my view:
Code:
<input type="hidden" id="artist-id" name="record_artist_id" value="<?php echo set_value('record_artist_id', $record_artist_id); ?>">

I thought I had to use the input helper so I tried:
Code:
<label for="record-name"><span class="required">*</span>Name:</label>
                   <?php
                   echo form_input([
                       'type' => 'text',
                       'name' => 'record_name',
                       'id' => 'record-name' ,
                       'class' => 'form-control',
                       'value' => set_value('record_name')
                   ]);
                   ?>

But still not working.
This is working though:
Code:
<input id="record-name" name="record_name" type="text" value="<?php echo (isset($record_name)) ? $record_name : ''; ?>" class="form-control">

The form helper is being loaded in autoload.php
Code:
$autoload['helper'] = array('url', 'file', 'form', 'base');

I don't know if this is related but I'm getting the view as a string and then passing it to a template, something like:
Code:
public function add_content($view, $content = NULL){
       $this->content = $this->load->view($view, $content, TRUE);
       return $this->content;
   }

and later on in a different method:
Code:
// render content
           $this->load->view('partials/content', ['content' => $this->content]);

Any idea about what I am doing wrong?
Reply
#2

PHP Code:
<?php
echo form_input([
    
'type' => 'text',
    
'name' => 'record_name',
    
'id' => 'record-name' ,
    
'class' => 'form-control',
    
'value' => set_value('record_name',$record_name)
]);
?>
Reply
#3

(This post was last modified: 03-15-2019, 01:07 PM by pippuccio76.)

i have the same  problem  the hidden fields arent set.

How can i solve it ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB