CodeIgniter Forums
[HELP] Form Generation Library (radiogroup ) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: [HELP] Form Generation Library (radiogroup ) (/showthread.php?tid=51373)



[HELP] Form Generation Library (radiogroup ) - El Forum - 05-01-2012

[eluser]ci_mohammed[/eluser]
hi all Smile

this is my first Topic in the forum , i hope to find some help ,

can some one tell me how to use radiogroup in Form Generation Library.

pls some one tell me how to use it in controller and model .

i trying to use it but i faced some problem .

here is what i do
in model

Code:
$news->isInMain = $data['isInMain'];
$news->isactive = $data['isActive'];
$news->can_comment = $data['can_comment'];

in controller
Code:
$isInMain[] = array(1, 'yes');
$isInMain[] = array(0, 'no');

$isActive[] = array(1, 'yes');
$isActive[] = array(0, 'no');

$can_comment[] = array(1, 'yes');
$can_comment[] = array(0, 'no');

$this->form->radiogroup('isInMain', $isInMain, 'isInMain:', '1', 'required')->br();
$this->form->radiogroup('isActive', $isActive, 'isActive:', '1', 'required')->br();
$this->form->radiogroup('can_comment', $can_comment, 'comment:', '1','required')->br();


this it error msgs that i faced
-------------------------------------
A PHP Error was encountered

Severity: Notice

Message: Undefined index: isInMain

Filename: models/News.php

Line Number: 29
------------------------------------

------------------------------------
A PHP Error was encountered

Severity: Notice

Message: Undefined index: isActive

Filename: models/News.php

Line Number: 30

------------------------------------

------------------------------------
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: mysql/mysql_driver.php

Line Number: 552

------------------------------------


can some one tell me the problem ..

or to tell me how to use it step by step , and i will be very grateful .


[HELP] Form Generation Library (radiogroup ) - El Forum - 05-01-2012

[eluser]S-Vizion Software and Development[/eluser]
Could you post some more of your code?

A undefined index means your array does not have a key named whatever your error is try something like below

Code:
// Type Cast Variable Data as a Array
$data = (array) $data;

// First check there is a Array Key named 'isInMain' and then check it's not empty
if (array_key_exists('isInMain', $data) && !empty($data['isInMain'])
{
  // Set Object Key to the Data
  $news->isInMain = $data['isInMain'];
}

if (array_key_exists('isActive', $data) && !empty($data['isActive'])
{
  $news->isInMain = $data['isActive'];
}

if (array_key_exists('can_comment', $data) && !empty($data['can_comment'])
{
  $news->can_comment = $data['can_comment'];
}

I personally use a helper function myself that I wrote along time ago to verify that the variable I'm checking is set, not empty, etc to reduce having to write so much extra code checking.

Hopefully that will help you get on the correct track.


[HELP] Form Generation Library (radiogroup ) - El Forum - 05-01-2012

[eluser]InsiteFX[/eluser]
Try removing the colon!
Code:
'isInMain:'



[HELP] Form Generation Library (radiogroup ) - El Forum - 05-02-2012

[eluser]ci_mohammed[/eluser]
mmm the problem is how can i pass the checked value of radiogroup to model ??

then model insert it to database .

in controller
Code:
function addform()
{
  $this->form->open();

                $isInMain[] = array(1, 'yes');
                $isInMain[] = array(0, 'no');

                $isActive[] = array(1, 'yes');
                $isActive[] = array(0, 'no');

                $can_comment[] = array(1, 'yes');
                $can_comment[] = array(0, 'no');
  

  $this->form->fieldset('add');

  $this->form->radiogroup('isInMain', $isInMain, 'isInMain:', '1', 'required')->br();
  $this->form->radiogroup('isActive', $isActive, 'isActive:', '1', 'required')->br();
  $this->form->radiogroup('can_comment', $can_comment, 'can_comment:', '1', 'required')->br();
  
  $this->form->submit('save');
  $this->form->model('news','add_update');
  $data['form'] = $this->form->get();

  if($this->form->valid)
  {
   onsuccess('redirect', 'success');
  }
  else
  {
   $data['errors'] = $this->form->errors;
  }
  

  $this->load->view("addform", $data);
}


in model news.php
Code:
function add_update( &$form, $data)
{
  echo $data['isInMain'];
  echo $data['isActive'];
  echo $data['can_comment'];
}

in view addform.php

Code:
<?php echo $errors ?>
<?php echo $form ?>


what i need is when i checked yes in isInMain , and press save button ,
result = 1 .
but it is not hapend.


[HELP] Form Generation Library (radiogroup ) - El Forum - 05-02-2012

[eluser]ci_mohammed[/eluser]
--------------------
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: mysql/mysql_driver.php

Line Number: 552

---------------------


database
Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'Array' in 'field list'

INSERT INTO `news` (`isInMain`, `isActive`, `can_comment`) VALUES (Array, Array, Array)

Filename: C:\wamp\www\news\system\database\DB_driver.php

Line Number: 330

i should be
Code:
INSERT INTO `news` (`isInMain`, `isActive`, `can_comment`) VALUES (1, 1, 1)

but the value not pass