This is for Ubercart, but this is really a Views/Forms interface question.

I want to make an order form that will consist of multiple blocks (or panes), each of which has a view listing all of the products in that category.

I want each product listing to have one field that's a text input field, for the quantity the customer wants to order.

There should be one button on the page for putting the items in the cart. The submit code for that button should read all the text fields.

How is that best done? I know how to make forms, and I know how to make views, but I don't know how to spread a form over multiple views.

Comments

DanZ’s picture

Views Bulk Operations does this for checkboxes, and #769322: Create the "View as form" style sounds like it enables it. So, it ought to be possible for text fields.

I think, though, that those only work for a single View at a time. How can a single submit button work for all the Views on a page?

--
www.ztwistbooks.com. Math books that are actually fun.

DanZ’s picture

There's a pretty good explanation of some of this at https://isovera.com/blog/programmatically-creating-forms-views-drupal-7, but there are still a few pieces missing.

Once the form fields are in Views, how should they be put into an actual form? Once that's done, how does the submit button connect with the individual views?

--
www.ztwistbooks.com. Math books that are actually fun.

DanZ’s picture

So, does anyone know? I'm pretty sure I can see how to put form fields into Views, but:

What's the right way to get those Views on a page with a submit button?

How should the callback for that submit button get all the values in those fields from all those different views?

It seems like it should be simple, but I can't find documentation on this anywhere.

--
www.ztwistbooks.com. Math books that are actually fun.

DanZ’s picture

Does anyone know of a guide for how to do this sort of thing? I can't find one.

--
www.ztwistbooks.com. Math books that are actually fun.

DanZ’s picture

Does anyone know about mixing up Forms and Views?

--
www.ztwistbooks.com. Math books that are actually fun.

WorldFallz’s picture

I don't think your post is being ignored, I think you're in pretty edge case territory and you might do better to post to the ubercart issue queue about the functionality you're trying to create (rather than specifically posting about forms and views).

DanZ’s picture

Yeah, it's looking like I'm going to have to experiment and see what happens. Maybe with Panels....

I figured that there aren't a lot of people who would know this stuff, but someone must. I'm just hoping for a direction so I don't waste a lot of time trying something that could never work before blundering onto the right solution.

In any case, this isn't really an Ubercart thing. The views will be constructed based on a normal taxonomy. The forms will be brand-new things. It will only be the submit function that will do anything having to do with Ubercart.

Isn't there some document out there that explains the whole data structure for building a page? I think forms are just one part of that, and maybe it would apply here. I haven't dug much into that, and I can't find the doc.

--
www.ztwistbooks.com. Math books that are actually fun.

goofus’s picture

Hello,
I'm not sure what you actual requirements are. So it might benefit you, if you provided an elaboration of your requirements?

For example, is your requirement literally 'I must use the contributed module "views" and the Drupal form api (FAPI)"? Or is there some services that "views" performs, that happen to match your required functionality?.

Your requirements could be the following:
I have a 100 records.
I need to display 10 records at a time (I.E. a 10 record pager).
The 10 records are displayed in an html table.
The html table header contain links that allow the user to sort by the column/field.
Each row in the html table also contains a modify and delete control.
.... etc, etc,

All of the above can be done with Drupal's core api. Take a look at core administrate (manage) "users" or "content". But again, maybe there is some other function that only "views" can perform? It might help if you specify what that function is :)

To summarize, it might help if you specify a little further :) Note! Your original post is a good explanation. However, you then introduce terms like "views on a page". Sorry, that lost me. Maybe you just want to compare the cost/benefit of many forms (one form per row) versus (cost/benefit of ) one form for many rows?

Again, sorry for all the speculation,

Good Luck

DanZ’s picture

Very well.

I want to make an order form for wholesale customers of my Ubercart store. The form should provide an easy, fast way for the customer to see all our products (currently a little over 30), type in the quantity they want for each, and add them to the cart. There should be no page loads until the customer actually orders the items.

Ubercart products are nodes (of type "product"). There is a taxonomy for products so that they can be arranged into a catalog.

Customers normally navigate to a product's node page or catalog page (which is a view) to add each item to a cart. There is a page load each time an item is added. This is too slow for wholesale customers.

So, I'm proposing an order form page. Each category of product is represented by a Views table, which lists all the products, one per line. Each line has a form field for quantity. All the category Views tables are there on the same page. There's a single submit button on the page. Clicking it updates the customer cart with the appropriate quantities of each product.

(Note: This starts to get ugly when you consider that a product can belong to multiple categories and that the same product can have different attributes, but I'll worry about that another day.)

So, I'm proposing Views because Views handles tables, DB lookups, sorting, taxonomies, and form elements well, and I want all those things.

--
www.ztwistbooks.com. Math books that are actually fun.

goofus’s picture

Hello,
Thank you for the reply. I don't know what "node page", "catalog page" or "Views table" mean. Thus, I can't offer any specific advice.

What I did understand is, you need to improve performance. Thus, I would consider profiling your process and identifying where your bottlenecks are. You could start by doing something simply like using Chromium (web browser) Developer tools. The network analyzer details the transport time of each hit (image, js script, etc). You can also run "Audit" to get some recommendation.

I would also consider taking a look at your database engine's optimization tools. You may find that adding some additional indexes to your tables improve performance. Many database engines include utilities to help you improve database execution paths.

Neither suggestion is intended as an "instead of" you idea. I'm suggesting these as "in addition to".

Hope that makes sense :)
Good Luck.

DanZ’s picture

I don't know what "node page", "catalog page" or "Views table" mean.

A node page is a Drupal Web page that has a full display of a single content node. You're looking at one now.

A catalog page, in this case, is a page that displays a list of the items in a category of the Ubercart catalog. This category is classified by a standard Drupal taxonomy.

A Views table is an HTML table that is defined and constructed using the Views module and displayed on a page.

--
www.ztwistbooks.com. Math books that are actually fun.

jaypan’s picture

I'm not sure that you could put together a list of views like this using the views module, though to be fair I don't use it that much, so it may be possible in some way I don't know. I know that when creating a view, you can choose block, page, or attach. If you created a bunch of 'attach' views, maybe you could attach them to a page and see if that works?

If not, then I'd do something in code. You can use, I believe, views_get_view() to get a view and render it. You will need to pass in the applicable data. You can then in code get all the views you need/want, and put them together in a page using code, rather than the admin interface.

Contact me to contract me for D7 -> D10/11 migrations.

DanZ’s picture

Jaypan, yes, that is what will have to happen. The page will have a Views table for each term in a taxonomy. Since the contents of the taxonomy will be different for every site, that will have to be generated dynamically.

The (current) issue is dealing with the form fields in the views. There doesn't seem to be any good documentation on form fields in views, much less form fields spread over multiple views.

--
www.ztwistbooks.com. Math books that are actually fun.

WorldFallz’s picture

I've no clue how to handle the spreading over multiple views, but you can use the editablefields module to enable form fields i a single view. I use it all the time and it works great.