Part of the EllisLab Network
   
 
generate a form from a db table - not quite
Posted: 17 July 2007 10:20 AM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  07-17-2007

I am a beginner at this - and don’t quite get it.
I am almost using “generate a form from a db table” which says I can use the formbuilder function by itself. I can’t seem to get it to work though.
Using the example given I have in controller/managetables.php

<?php
Class Managetables Extends Controller

    
function index()
    
{
    $template[
'xajax_js'$this->xajax->getjavascript(null'http://localhost/custom/javascript/xajax.js');
    
$attributes = array('name'     => 'sectionContentForm',
                      
'id'       => 'sectionContentForm',
                      
'onSubmit' => 'xajax_addUser(xajax.getFormValues(\'sectionContentForm\'));return false;');
      
    
$formOutput form_open('#',$attributes);
    
$formElements $this->_formBuilder('users');
    foreach(
$formElements as $name => $htmlTag){
        
    $formOutput 
.= '<label for="'.$name.'">';
    if(
stristr($htmlTag,'type="hidden"')){
      $formOutput 
.= $this->$name.'</label><br />'.$htmlTag;
      
$displayName str_replace('<input type="hidden" name="'.$name.'" value="','',$htmlTag);
      
$displayName str_replace('" />','',$displayName);
     
$formOutput .= '<b> -- '.$displayName.'</b><br />';
    
else {
      $formOutput 
.= $this->$name.'</label><br />'.$htmlTag.'<br />';
    
}
  }
  $formOutput 
.= form_submit('submitContentForm','Create').form_close();

    
$template['formOutput'=  $formOutput;
    
$this->load->view('managetables'$template);
    
}


function Managetables(){
  parent
::controller();
  
$this->load->library('xajax');
  
$this->load->helper('url');
    
$this->load->helper('form');
    
$this->load->helper('html');
  
$this->xajax->registerFunction(array('toggleManagement',&$this,'_toggleManagement'));
  
lots more here ...
}
  
function _formBuilder($table,$values=array(),$valuesAsHidden=FALSE){
  $columns 
$this->db->query($this->db->_list_columns($table));
  if(
$columns->num_rows() > 0){
    
foreach ($columns->result_array() as $columnInfo){
      
foreach($columnInfo as $key => $val){
        
if($key == 'Field'){
          $fieldName 
$val;
          
// if(!$this->data->getManagementStatus($table,$fieldName)) break;  //comment this out if you are using only this function and not the supporting "management" fuctions
        
}
        $arrTableInfo[$fieldName][$key] 
$val;
      
}
    }
    $formDisplay 
'';
 
lots more here ...

and in views/managetables.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<?php echo $xajax_js;?>
</head>
<
body>
<?php echo $formOutput ;?>
</body>
</
html

I get an error message at the top for every field in the

A PHP Error was encountered
Severity
Notice
Message
Undefined propertyManagetables::$id
Filename
controllers/managetables.php
Line Number
22

A PHP Error was encountered
Severity
Notice
Message
Undefined propertyManagetables::$last_name
Filename
controllers/managetables.php
Line Number
22 

and then I also get the form, but only the input line - no label?

anyhelp?
thanks

Katherine

Profile
 
 
Posted: 17 July 2007 12:13 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  5
Joined  07-05-2007

I don’t know if this solves the problem, but you need the Constructor at the start of your class, not in the middle of it. Swap ‘Managetables()’ and ‘index()’ around.

I hope I’m right with that.

Profile
 
 
Posted: 20 July 2007 10:36 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  2
Joined  07-17-2007

Nope, that didn’t do it…

Profile
 
 
Posted: 20 July 2007 03:18 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1092
Joined  08-06-2006

erm… this is a PHP error telling you that you haven’t told the class that it has properties (Undefined property).

You need to understand classes and objects better - I suggest reading about object-oriented techniques in PHP.

the short answer:
put this right after the class opening bracket…

var $id;
var 
$last_name

cheers

EDIT:
ps. if you post code, post *all* of the code… don’t put “lots more here” and snip the code away.

 Signature 

peeker email (imap/pop) | site_migrate | OOCalendar | PhotoBox2 | word_limiter

Profile