I'm currently developing a custom module for my company and have run into quite an issue.
I created a function to render a form, however, the checkbox options need to be dynamic based on the term_data table....so I tried this:
function render_video_options(){
$output = '';
$query = mysql_query("SELECT * FROM term_data WHERE vid = '9'");
while ($row = mysql_fetch_array($query)){
$output .= "'".$row['name']."' => t('".$row['name']."'),";
}
return $output;
}
The point of this function is to create an output variable that will loop through every entry in the term_data and put it into a
'name' => t('name'), format to fit the drupal form api standard.
Then I implement this, hoping to put in the $output variable in place of the options array to populate the array:
$form['videosowned'] = array(
'#type' => 'checkbox',
'#title' => t('Videos Owned'),
'#options' => array(
render_video_options()
),
);
However, it only prints a checkbox and then the literal string of " 'name' => t('name'), " as a STRING, not as variable input for the array....
Also, although it was doing that before, I tried it again and now it's just printing out a checkbox and then the title of the form (I.E. Videos Owned).
Can someone help me out here?
Unfortunately, I can't reference to a link as the project is on a private vpn of the company.
Comments
#optiions should be an array of value label pairs
#optiions should be an array of value label pairs, so your first function should look something like
which will produce an array indexed by tid with the values being the corresponding name.
Then your next piece of code would look like
Note your validate and submit functions will see the choice as a term id (tid). Generally it is better for the code to work with tid's (while showing the user names) since the name can change (while the tid stays the same).
Also you may wish to implement the taxonomy hook so if someone deletes a term you can clean up any stored data.
Thanks nevets! Worked like a
Thanks nevets!
Worked like a charm, however, one typo in your code:
checkbox -> checkboxes
:)
Thanks again.
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
See what happens when you copy :)
And I copied from your orignal post :)
Ha! Well how about that, I
Ha!
Well how about that, I guess it really is hard to find any typos until you get a fresh pair of eyes.
Thanks again. :)
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
Any clue as to why this
Any clue as to why this wouldn't return the variable?
I'm just trying to get it to output the divs in the $output variable, but for some odd reason, it won't. Forgive me if this is relatively simple, I've been coding all night and everything's starting to blur together.
Also, would anyone perchance know if there's a hook to add a javascript body onload? I.E.
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
Never printed so never output
Your code (second snippet) only calls render_usercalendar(), it never does anything with the return value. I am guessing you want something like
As for running javascript the preferred way is to use the jQuery ready event, something like this
As for the output, duh.
As for the output, duh. Again, I apologize, it's been a long night.
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
as for the js: would it look
as for the js: would it look something like:
or am I completely off-base, and jQuery, do you mean the built in js or the module?
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
You got it
And by jQuery I mean the library (it gets included as a side effect of calling drupal_add_js)
Just not liking me
from the calendar.js file:
and it's not doing anything except outputting a blank div, I know the function called should be navigate("","") ...it works fine on an html with that as the body onload
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
A couple of things
Given the function as arguments you need to set up the js like
(It does not really need to be multiline, I just find it easier to read and edit that way).
And in your calendar.js the url is probably wrong as it will be relative to the path used to construct the page. So for example iif the path you are using was www.yoursight.com/calendar, the url would translate to '/calendar/calander.php' which is probably not where the script is.
(The net tab of firebug is useful for tracking this kind of problem)
And as a side note your navigate function using jQuery could be coded something like (does not fix path issue though)
(You will probably want to set dataType to reflect the information returned by calander.php, you can also set 'error' to a callback to handle errors)
Nothing but a "Parse error:
Nothing but a "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kenaiw/drupal/modules/usercalendar/usercalendar.module on line 137" error...
line 137: $block['content'] = $content;
*headache*
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
First part is PHP code
This part
is PHP and replaces the orignal setting of $js (so that arguments to navigate are handled).
My bad, it was in the php
My bad, it was in the php script, but I copied and pasted AFTER I moved it, so it originally was in the .module.
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
I am unclear, are you still getting the error?
If you are still getting the error what do the lines right before the line with error look like?
It seems to switch off
It seems to switch off between the parse error and nothing (i.e. no errors whatsoever, but also, no output).
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com
I do not see a closing quote
This part
has no closing quote. If that is not the problem send me the source file and I will look at it the morning.
Hey Nevets, Sorry I didn't
Hey Nevets,
Sorry I didn't get back to you yesterday, full with meetings. I got it fixed though thanks to your direction. This is what it looks like when working:
Now I just need to figure out how to pass a variable from the module file to the external .php file. Hopefully it'll be easier than what I'm anticipating. Thanks! :)
------------------------
Cassandra Wolff
PHP Developer
Gaiam Inc.
Direct: 303-222-3676
cassandra.wolff@gaiam.com