$node access from QForm

Login or register to post comments
10 replies [Last post]
Offline
Joined: 11/18/2008

I'm working with the new release of QDrupal attempting to port over my forms that worked with the previous version of QDrupal. I started out by creating a basic form (unrelated to my old forms) and I've been able to successfully render the form in the node, however I cannot access drupal's $node variable. I executed get_defined_vars() while inside the QForm and only found the variables passed into qdrupal_run_qform function. With the new version of QDrupal, is there a new way to access $node and other drupal variables?

Thanks!

Offline
Joined: 11/25/2008

I did a little test and got this working:

<?php
global $GLOBALS;
class
FirstForm extends QForm{
protected function
Form_Create(){

$x = $GLOBALS;

var_dump($x['user']);
}
}
?>

Offline
Joined: 07/10/2008

I believe you can just do global $node;

You have access to all of drupals functions inside the form, if you want a drupal varaible just add the global in front of it..

Offline
Joined: 11/18/2008

Thanks so much for the replies-

I tried declaring global $GLOBALS outside before the form_create function. I was able to get the $user object as you had indicated, though $node was not found in the array.

I also tried just accessing global $node and I could not access the node information either ($node came back null/undefined).

Offline
Joined: 11/18/2008

Just to clarify, I still haven't been able to successfully access the Drupal $node variable.

I'm currently getting around it by passing in the node when running qdrupal_run_qform instead of just the $node->title (and subsequently changed the qdrupal_run_qform function as well), though I'd prefer not to change QDrupal code if the $node variable can be accessed any other way.

Any ideas?

Offline
Joined: 11/18/2008

Mike Hostetler sent me an email with the following solution inside the qform's Form_Create(), which I tried out and it works just fine.

$nid = arg(1);
$objNode = node_load($nid);

Thanks Mike.

alex94040's picture
Offline
Joined: 11/06/2008

Phobulous - if you can do a write-up on how to integrate QCubed with Drupal, it'd really, really help the community. Would you be up for it?

Offline
Joined: 01/14/2010

Looks like the author has massive awareness in the subject. Thanks you for the info