Wednesday, November 26, 2008

Hiding a form fieldset in Drupal

I am working on a dating site. Because it's a dating site, I need sign-ups for it to work. Without members, I won't get sign-ups. My idea: give the first 50 people token gift cards in exchange for signing up and taking part. But, how do I prevent hundreds of people from cashing in on this deal? Here's one way:
  • I have node_profile in place (AWESOME module)
  • In the "profile" content-type, I put in a field group for the Incentives
  • In the Incentives, I have two fields. One is a select dropdown
  • In the dropdown, I added the code below to the "php code" in the field administration
  • When the code fires, it looks at the user id numbers in the sequences table. If the number is below a threshold, it will return the array of values. If the number is above, it will return an effectively empty array; it will also do a drupal_add_css() to load to add css to mask (display: none) the fieldset from public view. It doesn't entirely hide it, but it does keep it out of sight from casual users.

$max = db_fetch_object(db_query("SELECT id FROM {sequences} WHERE name = 'users_uid'"));

if ($max->id < 1111111163) {
return array(
'Starbucks' => 'Starbucks',
'Serious Coffee' => 'Serious Coffee',
'iTunes' => 'iTunes',
'EB Games' => 'EB Games'
);
}
else {
return array('n/a' => 'n/a');
drupal_add_css('themes/callme/no_incentive.css');
}

No comments: