I'm using the SignUp module for a convention schedule application I'm writing. What's the best way to allow signups for a node programmatically? Do I just add all the fields "by hand" then node_save? Or is there a function I missed?
Thanks
I'm using the SignUp module for a convention schedule application I'm writing. What's the best way to allow signups for a node programmatically? Do I just add all the fields "by hand" then node_save? Or is there a function I missed?
Thanks
Comments
Comment #1
Gremdel commentedI dug a little deeper into the SignUp code and I think I may have figured this one out. At the very least, it seems to work. Please let me know if there's a better way to do this:
Thanks! Hopefully this will be of some use to someone.
Comment #2
Gremdel commentedAll right, newish problem: How do I change the maximum number of signups allowed? Here's what I've tried (using above code):
and when that didn't work I tried:
I've also tried setting them to an integer instead of a string. Any suggestions?
-Thanks
Comment #3
dwwRe: #1 -- yeah, that's basically it.
However, you have some problems with this code, most seriously, an XSS (cross site scripting) vulnerability:
Not only is it not translatable (and themers will hate you for the raw HTML), this opens you up to XSS via the node title. Instead, you want this:
See http://api.drupal.org/api/function/t/6 for more.
Also, while I'm reviewing your code:
There are a couple of issues in here:
1) If you use node_load() like that, the node_load() cache can't be used (so it's much more expensive). If you just try to load via the nid, the node_load cache is used.
2) Code style is wrong on the
if(since the { should be on the same line).So, I'd write this like so:
This assumes $id is an integer. If you can't trust the $id (depends on the caller for safety), you can always cast it to an integer, like so:
Re #2: The signup settings themselves aren't handled via node_save() anymore. See #578502: Move signup-related settings from node/N/edit to node/N/signups/settings. So, there's no real API for modifying the signup settings on a node -- it's all form-based, which is evil. My apologies. See signup/includes/node_settings.inc for more, in particular signup_node_settings_form() and signup_node_settings_form_submit(). Ugh.
The simplest way is to do the query yourself:
But, that's still evil.
Really, there should be an API for this, something like:
This function should do the above query, and is what should be called by signup_node_settings_form_submit() to save the values. Then, other callers could use the same function to do the same stuff, without either having to directly touch the DB nor messing around with faking form submissions, etc.
Changing title and metadata about this issue to reflect that this task should be done, it's not just a support request anymore. Patches welcome. ;)
Cheers,
-Derek
p.s. the
filtering stuff on drupal.org is messing with the whitespace a bit, so the above is not formatted to match the Drupal coding standards. Don't let that fool you. ;) It should have a leading space before each ' *' and before the ' */'...Comment #4
Gremdel commentedThanks for all the input, Derek, it's really appreciated. Here's what I've done based on your suggestions (and it seems to work):
Thanks again and for going to extra mile to help with drupal in general.
Comment #5
socialnicheguru commentedsubscribing
Comment #6
socialnicheguru commented@Grendel et all,
I am having the same issue.
I tried doing it in rules, but the value for signup_close_signup_limit is overwritten at some point after I execute the rule. I tried using php execution for it. but that didn't work.
Edit.
I created a php rule and just accessed the database.
The api for signup settings would really help