Building a Module - How to get two actions on same page?

No replies
tim3
Offline
Last seen: 5 years 40 weeks ago
Joined: 2012-06-01

I'm using "build a module" course, but can't figure out how to accomplish a specific task, which should not be too difficult. I think. I've created a sample scenario, for the sake of practice.

Users are able to enter products and product numbers into a database.

I'd like for a user then to be able to enter a product number and have the module automatically output the price & ask for another product number. Would I use the form_submit() function to output the results? If so, how (any clues appreciated)?

NOTE: I'm looking to output the results on the page (not in the message area, ie - drupal_set_message).

Another way of stating my goal: I want the user to be able to input data on a page, click submit and have the data processed and used to generate additional output (not in drupal message window), without the user having to navigate to another page.

      • Sample Code - - - - -

function demo_form($form, &$form_state) {

$form['product-number'] = array(
'#type' => 'textfield',
'#title' => t('Item'),
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE,
'#description' => t('Please enter a product number'),
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);

return $form;

}

function demo_form_submit($form, &$form_state) {

//* Is this the right function? What do I do to print [product] ? */

}

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.