0

I'm struggling to find a working method for populating the key & value pairs of a select field (created with forms api) with data from a view.

e.g.. I have a view of 'location' content types.

In the form I've created I need a drop down showing all these location names and a reference from their content type as the key.

Can anyone suggest the easiest method?

  • why does it need to come from a View? why not retrieve the information directly from the db? – Geoff Jun 19 '14 at 17:35
  • Good point - no good reason I suppose, would that be your preferred method? – steve Jun 19 '14 at 20:17
  • 1
    since you're only retrieving very limited information, and providing the end user has no control over what information is retrieved, that's how I would do it... but that's just an opinion of course. There's lots of resources on db retrieval to look at. Here's a some info on securely writing: drupal.org/writing-secure-code – Geoff Jun 19 '14 at 20:27
  • I ended up using node_load_multiple as all the data needed was from the same content type. Seemed somewhat faster than querying directly - any disadvantages to this approach? – steve Jun 19 '14 at 23:09
  • 1
    none that come to mind - it should take care of most of the retrieval security issues as well. – Geoff Jun 20 '14 at 0:09
0

In lieu of using Views to handle the query, for performance reasons you are probably better off doing something more direct with the db, just make sure that you follow standards for security when accessing the db via any method. Here is a link to the Writing Secure Code documentation - a must read for anyone delving into this area.

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.