⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

several fields in a row in add/edit form



miquel

miquel
  • profile picture
  • Member

Posted 26 September 2016 - 13:16 PM

Hello.

 

I'm trying to place two (or several)  fields side by side instead of one row each. Example, if the form asks for name and gender, both fields could be placed in one row instead of two. Currently grocery place the fields one each row. The lenght of each field is easy controled by using a callback.

 

now

 

 name : ________________________  

gender: ___

 

desired behavior

 

 

name : ________________________   gender: ___

 

 

 


miquel

miquel
  • profile picture
  • Member

Posted 28 September 2016 - 08:50 AM

I answer my question.

 

1: hide de second field

 

 $crud->field_type('gender','hidden');

 

use a callback function

 

    $crud->callback_field('name',array($this,'field_name'));

 

put both input on callback funcion

 

function field_name($value)
{
    $result='<input type="text" maxlength="10" value="'.$value.'" id="name" name="name" style="width:100px">';

    $result .='<input type="text" maxlength="10" value="'.$value.'" id="gender" name="gender" style="width:100px">';

    return $result
}

 

Still have a problem.


miquel

miquel
  • profile picture
  • Member

Posted 28 September 2016 - 08:52 AM

The problem

 

in add mode works fine

in edit mode. I just get the value of name, but not the value of gender.

 

How can I pass two parameters to the funtion ??

 

thanks, and congrats for this wonderful piece of software.

 

       Miquel.


miquel

miquel
  • profile picture
  • Member

Posted 29 September 2016 - 09:57 AM

Again, solved.

 

In the call function add the code to get the row from the database and collect the information,

 

zona and datum are fields we are looking for. CSite is the primary key of the table site.

 

    $this->db->select('zona,datum');
    $this->db->where('CSite', $primary_key);
    $result= $this->db->get('site')->row();
    // If the row is empty, set the variables to something
    if ($result == NULL) { $value_zona=''; $value_datum=''; }
    else { $value_zona = $result->zona; $value_datum=$result->datum; }

 

After the code you have the values in $value_zona and  $value_datum

You can use in the input box. For example:

 

<input type="text" maxlength="7" value="'.$value_datum.'" id="datum" name="datum" style="width:75px">

 

 

Miquel.


ingafriyie

ingafriyie
  • profile picture
  • Member

Posted 23 April 2018 - 17:26 PM

Nice.

But I would be grateful if you could have demonstrated the last part using the name and gender example.

Thanks.