Posted by verbosity on September 9, 2010 at 2:38pm
hi,
Firstly apologies since this is an obvious noob question, but I've been unable to find an answer for it.
I'm writing a module that requires a simple check box in various content types ( preferably making it a sort of 'default' field like Body or Input format). I've no idea how to code this option ( which I'd need to do if I wanted to release this into the wild) I've done a search or two, but I have to admit to being throughly lost on this.
Thanks in advance.
Verbosity
Comments
simple example about checkbox
$options = array(
'poison' => t('Sprays deadly poison'),
'metal' => t('Can bite/claw through metal'),
'deadly' => t('Killed previous owner') );
$form['danger'] = array(
'#title' => t('Special conditions'),
'#type' => 'checkboxes',
'#description' => (t('Please note if any of these conditions apply to your
pet.')),
'#options' => $options,
'#weight' => 25,
);
For a beginner I highly
For a beginner I highly recommend the book Pro Drupal Development. You can see it here:
http://www.amazon.co.uk/Pro-Drupal-Development-VanDyk/dp/1590597559/ref=...
Looking at the code in the last post, I'm sure the poster would recommend it too!
Systemick
Drupal is the daddy of all content management systems.
www.systemick-web-development.co.uk
Check out the examples
Developers examples located here http://drupal.org/project/examples
@ sunwin : Thanks for the
@ sunwin :
Thanks for the example, once again I think I've not explained myself. What I'm looking at doing is making a CCK field that admins themselves can add to content types. making a checkbox itself isn't the issue.
Currently I've got my array with the checkbox in a form_alter hook that uses if($form_id=='book_node_form') ( which suits my own needs), but I'd much rather have a way of just creating the field, and checking if its included in a content type.
@systemick:
Thanks I'll check it out, looks like an interesting book.
@goofus:
Thanks looks really interesting, but there is no field api example which is really what I was asking about
hi as a follow up... I've
hi as a follow up...
I've decided that at the content creation stage I can just include a check-box which appears depending on permissions.
Would I be correct in guessing that node_type_form would be the form for any content type that is a node? And if so will it appear on editing the node as well?
Since I've went for a default form edit the examples above were useful ( thanks), Though some reference for coding a CCK field would be pretty cool too ( I can see myself having uses for that.