2

I'm trying to create a bar code generator like the one at http://qr.insready.com/node/add/vcard . This generator is created with Drupal 7 & the Barcode contributed module (by the module's creator).

What I need my application to do is accept a number of items of user data input into a form, concatenate the field entries using tokens into the barcode input field, then generate a bar code on form submit as well as save the data into a database.

This is what I've accomplished so far. I have created a custom multi-part form module following the example in the Examples module, & got it to input data into the database. (I don't know if this will be exposed to Views, since I'm learning this as I go; it's a table I created within Drupal's database specifically to store the data.) Independently, I have created a custom content type with a barcode field that gets tokens from other fields in the form, & successfully creates a bar code encoding the data from the fields in concatenated form.

I would appreciate some pointers on getting this working together. What I need is a way of getting the barcode field into my custom form. Then it can pull data out of the other fields using tokens just as with the custom content type I created.

I can post code snippets if they are needed.

  • 1
    So the question is how to get a form element for a field into a custom form? – googletorp Feb 2 '12 at 21:34
  • Yes, how to get the barcode field into the custom form. – hclayton Feb 2 '12 at 21:50
1

field_attach_form is the function used to attach fields to forms. This will however attach all fields for a specific entity (fx a node type) to the form. So you most likely will need to do some work on removing unwanted fields or you could do something like this:

$form = array();
$fields = array();
field_attach_form('node', $node, $fields, $form_state);
$form['field_bar_code'] = $field['field_bar_code']; // Replace with your field name

You also need to invoke validation and submit on the field using field_attach_form and field_attach_submit. The data itself is saved when you save the node, all those functions do is populate the data on the node.

| improve this answer | |
  • I just ended up putting the field into a custom content type node creation form. Thanks for the pointers. – hclayton Feb 17 '12 at 7:16
1

Have taken a look at these modules. MERCI Barcode, Views Bulk Operations Barcode Select , Barcode

The first two are for Drupal 6 only so they will not work in a Drupal 7 site out of the box. If you save the files without installing them you can read the code and see what they did. The Third one has a beta for Drupal 7.x, so it can be installed. Feel free to borrow code to learn how.

As for getting it to work together...we would need specifics to provide answers. Ask about whatever your stuck on.

| improve this answer | |
  • The third module is the one I'm using (it's out of beta). I have it working & I have a custom form working. My specific question is what googletorp mentioned: I'm wondering how to get the field that the Barcode module creates into the custom form module so I can pass it tokens from the form & generate the bar code on submission. How do I get the Barcode input field into the custom form? – hclayton Feb 3 '12 at 4:12
  • I have not worked with barcodes. You may want to check the other modules to see how they did it. – Ashlar Feb 3 '12 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.