Welcome Guest, Not a member yet? Register   Sign In
Edit data
#1

[eluser]JohnnyBravo[/eluser]
Hi!

I'm newby here and in the world of CI too. I started to develop a little application, and I'm facing a problem.

So, I want to edit data in my database table. I get the original data from the table:

Here's my view file:
Code:
...
<div class="row">
        <label for="name" class="required">Csoportnév:</label>
        &lt;input type="text" name="name" id="name" value="&lt;?php echo set_value('name');?&gt;" class="text" /&gt;
    </div>
    
    <div class="row">
        <label for="crm">CRM!:</label>
        &lt;input type="radio" name="crm" id="crm" value="a" class="checkbox" &lt;?php echo set_radio('crm', 'a'); ?&gt; /&gt; Szerkesztés
        &lt;input type="radio" name="crm" id="crm" value="v" class="checkbox" &lt;?php echo set_radio('crm', 'v', TRUE); ?&gt; /&gt; Megtekintés
        &lt;input type="radio" name="crm" id="crm" value="n" class="checkbox" &lt;?php echo set_radio('crm', 'n'); ?&gt; /&gt; Nincs hozzáférés
    </div>
    
    <div class="row">
        <label for="register">Regiszter!:</label>
        &lt;input type="radio" name="register" id="register" value="a" class="checkbox" &lt;?php echo set_radio('register', 'a'); ?&gt; /&gt; Szerkesztés
        &lt;input type="radio" name="register" id="register" value="v" class="checkbox" &lt;?php echo set_radio('register', 'v', TRUE); ?&gt; /&gt; Megtekintés
        &lt;input type="radio" name="register" id="invoices" value="n" class="checkbox" &lt;?php echo set_radio('register', 'n'); ?&gt; /&gt; Nincs hozzáférés
    </div>
...

I can get the original data from the database, but how can I show them in this form from the database.

I hope, you understand it. Smile
I've tried the search function, but didn't find the answer (Maybe, I've choose wrong keywords...).

Thanks a lot!
#2

[eluser]rogierb[/eluser]
Use
Code:
set_value('name',$name)

Make sure you fill $name with either the post data or the database data

Code:
if($_POST){

    if ($this->form_validation->run() == FALSE)
    {
        $data['name'] = $_POST['name'];
    }else{
        // Success
    }

}else{

    $data['name'] = $row->name;

}
#3

[eluser]JohnnyBravo[/eluser]
Thank you, it helps me a lot!

I have one more question.
If I asked the original data from my table, and show it in my view, how can I display the actual state of a radio button.

view:
Code:
<div class="row">
<label for="crm">CRM!:</label>
&lt;input type="radio" name="crm" id="crm" value="a" class="checkbox" &lt;?php echo set_radio('crm', 'a'); ?&gt; /&gt; Edit
&lt;input type="radio" name="crm" id="crm" value="v" class="checkbox" &lt;?php echo set_radio('crm', 'v', TRUE); ?&gt; /&gt; View only
&lt;input type="radio" name="crm" id="crm" value="n" class="checkbox" &lt;?php echo set_radio('crm', 'n'); ?&gt; /&gt; No access
</div>

This code above is working, when I post data, but doesn't work, when I read data from my table.

Code:
...
$data['crm'] = $result->crm;
...
#4

[eluser]rogierb[/eluser]
try something like
Code:
set_radio('crm', 'a',$radio=='a'?true:false;)
set_radio('crm', 'v',$radio=='v'?true:false;)
#5

[eluser]JohnnyBravo[/eluser]
Thank you for your help. Everything works!




Theme © iAndrew 2016 - Forum software by © MyBB