Can you create a new fabrikViewForm in a custom template?

Status
Not open for further replies.

cookn22

Active Member
I don't want to render the form, just get access to "$whatever->groups['..']->elements" and "$whatever->_data" and such in the same way you can normally do with "$this". In other words, I want to be able to get data from "$this" as per usual but also have another fabrikViewForm object as well. Is this possible? I've tried sticking this code in my custom template:

Code:
<?php
global $database;
$attendance_form = new fabrikForm($database);
$attendance_form->load(29);
$attendance_view = new fabrikViewForm($attendance_form);
?>

and doing <pre><?php print_r($attendance_view); ?></pre> spits out

Code:
fabrikviewform Object
(
  [_template] => 
  [_errors] => 
  [_data] => 
  [_rowId] => 
  [_params] => 
  [_oForm] => fabrikform Object
    (
      [_tbl] => #__fabrik_forms
      [_tbl_key] => id
      [_error] => 
      [_db] => database Object
        (
          [_sql] => SELECT *
 FROM jos_fabrik_forms
 WHERE id = '29'
          [_errorNum] => 0
          [_errorMsg] => 
          [_table_prefix] => jos_
          [_resource] => Resource id #15
          [_cursor] => Resource id #472
          [_debug] => 0
          [_limit] => 0
          [_offset] => 0
          [_ticker] => 0
          [_log] => Array
            (
            )

          [_nullDate] => 0000-00-00 00:00:00
          [_nameQuote] => `
        )

      [_admin] => 
      [_aDataToIgnore] => Array
        (
          [0] => _frommodule
          [1] => ids
          [2] => option
          [3] => act
          [4] => task
          [5] => tableid
          [6] => Itemid
          [7] => limitstart
          [8] => pagelimit
          [9] => limit
          [10] => orderdir
          [11] => orderby
          [12] => sessioncookie
          [13] => mosadmin
          [14] => webfxtab_configPane
          [15] => webfxtab_content-pane
          [16] => PHPSESSID
        )

      [_reservedWords] => Array
        (
          [0] => _frommodule
          [1] => act
          [2] => task
          [3] => option
          [4] => form_id
          [5] => Submit
          [6] => ul_max_file_size
          [7] => ul_file_types
          [8] => ul_directory
          [9] => tableid
          [10] => rowid
          [11] => Itemid
          [12] => fabrik
          [13] => addDropDownValue
          [14] => addDropDownLabel
          [15] => ul_end_dir
        )

      [_nullDate] => 0000-00-00 00:00:00
      [id] => 29
      [form_title] => Attendance
      [record_in_database] => 1
      [form_introtext] => 
      [form_errmessage] => 
      [created] => 2007-12-20 00:00:00
      [created_by] => 62
      [created_by_alias] => admin
      [modified] => 0000-00-00 00:00:00
      [modified_by] => 0
      [checked_out] => 0
      [checked_out_time] => 0000-00-00 00:00:00
      [publish_up] => 0000-00-00 00:00:00
      [publish_down] => 0000-00-00 00:00:00
      [align] => left
      [width] => 100%
      [form_subject] => Attendance
      [form_submit_message] => 
      [form_submit_jumppage] => index.php?option=com_fabrik&task=viewTable&tableid=29
      [email_to] => 
      [email_from] => [email]ncook@uab.edu[/email]
      [receipt_email] => 
      [receipt_message] => 
      [reset_button] => 0
      [reset_button_label] => Cancel
      [submit_button_label] => Save
      [state] => 1
      [table_id] => 29
      [form_template] => bluesky
      [view_only_template] => bluesky
      [curl_code] => 
      [attribs] => email_on_edit=0
receipt_title=
append_jump_ul=0
save_full_elname_in_session=0
remove_table_filtres=0
only_process_curl=
scrollnav=0
email_template=
email=
print=
      [_elements] => 
      [_groups] => 
      [_table] => 
      [_aJoinGroupIds] => Array
        (
        )

      [_aDefaultFileTypes] => Array
        (
          [0] => .gif
          [1] => .jpg
          [2] => .png
          [3] => .bmp
          [4] => .doc
          [5] => .xls
          [6] => ppt
          [7] => .swf
          [8] => .pdf
          [9] => .dcr
        )

      [_editable] => 1
      [_enctype] => application/x-www-form-urlencoded
      [_formName] => 
      [_rootPath] => 
      [_js] => 
      [_validationRuleClasses] => 
      [_specGroups] => Array
        (
        )

      [_isModule] => 
      [_isMambot] => 
      [_aAttachments] => Array
        (
        )

      [_err] => 
      [_currentElement] => 
      [_aJoinObjs] => Array
        (
        )

      [_joinTableElementStep] => ___
      [_joinDefaultData] => Array
        (
        )

      [_params] => 
      [_menuParams] => 
      [_data] => 
      [_postMethod] => post
    )

)

There's no groups or elements in there, so I know I need to do some more stuff with $attendance_form, but I'm having a hard time figuring it all out.

Trying to think through how to use the formbot with what I'm trying to do makes my head hurt; I'm trying to put a customized form into the detailed view of another form that has multiple joins each with their own customized layout. It would be much easier if I could just get the elements and values straight from the other form.
 
Unfortunately its not quite as simple as that to load all the data. The code you are running simply loads the form definition, not the data. For a peek at what all is involved in piecing together the form data itself, have a look at render() in fabrik.class.php.

I just spoke to Rob, and there's a simple little hack we can make to render(), basically adding a "$render" argument. Then you could do ...

$attendance_form = new fabrikForm($database);
$attendance_form->load(29);
$attendance_form->render(blah,blah,false);

... so it loads all the data, but doesn't actually render it.

I'll make that change and test it ASAP for you, I'll let you know as and when I update SVN with this little hack.

-- hugh
 
OK, I've committed that change to SVN.

When you call render(), make sure you fill in the complete arg list, which is ...

Code:
	function render( $tableId = '', $rowId, $editable = false, $do_mf_pdf = false, $admin = false, $usekey = '', $render = true ){

So something like ...

$attendance_form->render(3, 29, false, false, false, '', false);

And remember, your tableid probably isn't the same as the formid. Actually, you can specify 0 for tableid and it'll grab it from your form def. But obviously you gotta give it the rowid you want to load.

Let me know how you get on.

-- hugh
 
Ok, here's an update:

The render function hack works perfectly, but I still had the problem of getting the groups and elements into the familiar $object->groups['...']->element['...']->value/label/etc format. I figured out how to do this (sort of, I'll explain) with the following code:

Code:
<?php
      global $database;
      $attendance_form = new fabrikForm($database);
      $attendance_form->load(29);
      $attendance_form->render(29,9,true,false,false,'',false);
      $attendance_view = new fabrikViewForm($attendance_form);
      $attendance_view->display(NULL);
?>

Now this code throws up the following errors:

Code:
Fatal error: Call to a member function on a non-object in /home/apache/share/htdocs/uabsap/courtdb2/components/com_fabrik/views/form/view.html.php on line 110

Line 110 is
Code:
$this->showEmail = $this->_params->get( 'email', 0 );

Commenting out this code "fixes" this error and gives out another one:
Code:
Fatal error: Call to a member function on a non-object in /home/apache/share/htdocs/uabsap/courtdb2/components/com_fabrik/views/form/view.html.php on line 117

Line 117 is
Code:
$this->showPrint = $this->_params->get( 'print', 0 );

which is part of this block of code:
Code:
$pop = mosGetParam($_GET, 'pop');
		if( $pop != 1){
			if ( $this->showEmail ){
				$this->emailLink = fabrik_html_content::emailIcon( $this->_oForm, $this->_params ) ;
			}
	
			$this->showPrint = $this->_params->get( 'print', 0 );
			if ( $this->showPrint ){
				$this->printLink = fabrik_html_content::printIcon( $this->_oForm, $this->_params, $this->_rowId );
			}
	
			$this->showPDF = $this->_params->get( 'pdf', 0 );
			if ( $this->showPDF ){
				$this->pdfLink = fabrik_html_content::pdfIcon( $this->_oForm, $this->_params, $this->_rowId );
			}
		}

All of these assignments cause errors, so to "fix" this error I commented out the entire block of code, which leads to the next error:
Code:
Fatal error: Call to a member function on a non-object in /home/apache/share/htdocs/uabsap/courtdb2/components/com_fabrik/views/form/view.html.php on line 216

Line 216 marks the start of this block of code
Code:
			if($this->_oForm->_params->get('scrollnav')){
				$liveFile = $mosConfig_live_site . "/components/com_fabrik/views/form/scroller.js";
				$mainframe->addCustomHeadTag( "<script type=\"text/javascript\" src=\"$liveFile\"></script>" );
				
				if(mosGetParam($_REQUEST, 'task', 'viewForm') == 'viewForm'){
					$view = 'form';
				}else{
					$view = 'record';
				}
				$this->jsActions .= "rs = new recordSet( '$view');";
		}

After commenting out this code, my code works and the page loads and doing <pre><?php print_r($attendance_view->groups);?> </pre> spits out

Code:
Array
(
  [Attendance] => stdClass Object
    (
      [canRepeat] => 0
      [addJs] => 
      [delJs] => 
      [css] => 
      [id] => 60
      [title] => Attendance
      [name] => Attendance
      [delId] => 
      [addId] => 
      [displaystate] => 0
      [elements] => Array
        (
          [update_attendance___client_id] => stdClass Object
            (
              [label] => 
client id


              [error] => 
              [id] => update_attendance___client_id
              [int] => 381
              [element] => 

              [hovertext] => 
              [value] => 
            )

          [update_attendance___update_id] => stdClass Object
            (
              [label] => 
update id


              [error] => 
              [id] => update_attendance___update_id
              [int] => 382
              [element] => 

              [hovertext] => 
              [value] => 
            )

         
etc...
etc...

So....here's the list of things I'm going to tinker with to try and get this working:

1. Fix the errors in view.html.php (or make my form object not cause the errors):
a.line 110 error looks like $this->_params isn't being instantiated.
b.same thing with line 117 and its corresponding block of code
c.line 216 is, again, a problem with _params not being there, but its $this->_oForm->_params.

2.Figure out why the elements in $attendance_view don't have any values. They should..(I think)

3. Figure out how to get the created form object to act like its doing a viewForm task even though its created on a page where the task=viewTableRowDetails

So that's where I'm at. I think the first thing on the list will be fairly simple to fix (I saw some parameter-creating/messing with functions in fabrik.class.php that I'm thinking will help me figure out what to do), but I think 2 and 3 might be difficult.

Any more help you're willing to give on this project of mine would be appreciated!
 
I don't recommend anyone else alter the fabrik source!!!!

Ok, I fixed problems 1 and 2 with some edits to writeform and render in fabrik.class.php:

writeform edits...

On Line 377:
Code:
function writeForm( $arErrors, $data, $tableId, $rowId, $editable = '0', $do_fb_pdf='0', $admin = false){

Changed to:

Code:
function writeForm( $arErrors, $data, $tableId, $rowId, $editable = '0', $do_fb_pdf='0', $admin = false, $render = true ){

On Line 408 (409?)
Code:
$this->setPageTitle( $data );

Changed to:
Code:
if($render){$this->setPageTitle( $data );}

Code block around 452:
Code:
if( !$admin ){
					if( $this->_isMambot ){
						return $tmpl->display( $this->form_template );
					}else{
						echo $tmpl->display( $this->form_template );
					}
				}else{
					echo $tmpl->display( $this->form_template );
				}
			}
		}else{
			echo mosNotAuth();

Changed to:
Code:
if( !$admin ){
					if($render == false){
						return $tmpl;
					}else if( $this->_isMambot){
						return $tmpl->display( $this->form_template );
					}else{
						echo $tmpl->display( $this->form_template );
					}
					
				}else{
					echo $tmpl->display( $this->form_template );
				}
			}
		}else{
			echo mosNotAuth();

That's it for the changes to writeform, now the change to render, same file...

Somewhere around line 2615, (the recently altered render code):
Code:
$this->setAdmin( $admin );
		if ($render) 
		{
			if ( $this->canPublish( ) )	{
				return $this->writeForm( $arErrors, $formDefaultData, $tableId, $rowId, $editable, $do_mf_pdf, $admin );
			}else {
				if( !$admin ){
					fabrik_html_content::notPublished( 'form' );
				}else {
					$this->writeForm( $arErrors, $formDefaultData, $tableId, $rowId, $editable, $do_mf_pdf, $admin );
				}
			}
		}
	}
}

Changed to:

Code:
$this->setAdmin( $admin );
		if ($render) 
		{
			if ( $this->canPublish( ) )	{
				return $this->writeForm( $arErrors, $formDefaultData, $tableId, $rowId, $editable, $do_mf_pdf, $admin );
			}else {
				if( !$admin ){
					fabrik_html_content::notPublished( 'form' );
				}else {
					$this->writeForm( $arErrors, $formDefaultData, $tableId, $rowId, $editable, $do_mf_pdf, $admin );
				}
			}
		}else {
			return $this->writeForm( $arErrors, $formDefaultData, $tableId, $rowId, $editable, $do_mf_pdf, $admin, $render );
		}
	}
}

The code I put in my custom template to make the new fabrikViewForm object has changed a bit too, now it looks like this:
Code:
<?php
global $database;
$attendance_form = new fabrikForm($database);
$attendance_form->load(29);
$attendance_view = $attendance_form->render(29,9,true,false,false,'',false);
$attendance_view->display(NULL);
?>

So...I guess the problem I'm working on now is figuring out how to change the task for the $attendance_view object so I can have it do viewForm while the custom template it's stuck in is doing viewTableRowDetails. I worked on this for a couple hours but couldn't get anywhere... What I really want is to have the $attendance_view object have the same behavior as when you click on "Edit" in the table view,where it loads the rows values into the fields but you can edit and save the form.

When I looked at the different form objects that are created when you edit a form versus doing a detailed view, one thing that stood out to me was that the _cursor variable (in the _db object(s)) have different resource ids. I tried to do a mysql_fetch_array on _cursor but it didn't work...So yeah, I'm pretty much lost, but I'll give it another go tomorrow. If I could be pointed in the right direction I can maybe figure it out myself...maybe ;)

You've been a great help Hugh! I really appreciate all the help.
 
LOL! I like your comment about "I don't recommend anyone else alter the fabrik source!!!!". Yeah, it does get a bit deep in there.

I'll come back and take a look at all this after the holidays.

Speaking of which ... it's Christmas Day ... Merry Christmas!

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top