Hi all,
I'm trying to develop a form for a user to provide some information that will be used when rendering a block. One of the things I would like a user to provide is the number of posts they would like to see in the block, i.e., any integer value. This is being collected in a menu.inc file. I am collecting the value using #default_value and the #type is a textfield.
With this information, I would like to pass it to another function in my .module file using the variable_get function. However, when I do this and use the value, it appears it is being passed as a string and not as an integer (or number). As a result, my function simply displays all the posts available and not the number of posts as provided by the user.
how do you collect an integer from a user using the form field or is there a way to convert a string to an integer? Sorry if this is a no-brainer, I'm still learning...
Thanks
Comments
How are you getting the lists
How are you getting the lists of posts?
its actually a list of
its actually a list of twitter tweets that I am pulling from their site... They are populating properly because if in my .module file I put in an actual number like 2, it will show 2 tweeks but if I replace the 2 with the variable, i get all the tweets.
Toronto Website Developer
Without seeing the code I can
Without seeing the code I can only guess. My guess is the value is 0 and twitter treats that as return all tweets. You could add something like this to you code to check the value.
The message will show in the message area of the page.
great, that was something i
great, that was something i was struggling with, how to just have the value returned - I was short on time when working this morning, I was going to use the dsm function through devel. I'll try this out tonight when i am back at home and will post the results.
Thanks for the help.
Toronto Website Developer
To convert a string to an
To convert a string to an integer, you pass the datatype ahead of it.
note: The three equal signs (===) checks not just if the value is equal, but also if it is the same datatype.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for the help both of
Thanks for the help both of you. After I used the print statement I found out the variable was empty. After re-examining my code, I was using the variable_get() in the wrong location and it was outside of my function. After relocating it, my code is working properly.
Thanks very much for the help! As a side note, I didn't have to convert the value of the number, drupal just accepted it but its good to know how to change the data type, thanks for the info.
Pete
Toronto Website Developer