I'm basically creating my own interface for choosing among different product options, in Drupal 7, using Ubercart.
I want to manually create an html form where I will be submitting post variables which represent the details of the product(s).
Is this something possible to do? Is there any documentation on this? I hope it's simple enough.
Create a custom module ( lets call it mymodule )
register a valid url where your html form can be accessed use hook_menu
$items['mymodule/submit'] = array(
'page callback' => 'mymodule_submit',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
Now create the function mymodule_submit() in your module and use $_POST variable to check for values and act accordingly.
Related
Let's assume that I have commerce website on Drupal. There is Drupal Commerce module. I want use api to retrieve complete orders from my store. Is it possible? I can't find any information how this requests looks like (what is response format etc.). Also I don't need php examples , maybe is there Rest API?
I think there are few ways to do it, from simple to (a bit) complex.
Since you mention retrieving data only, the simple way is to create a new Views listing out all orders, you can configure this views to render output as XML or as JSON. Module used can be Views data export, or Views datasource.
The second solution is to create a custom module which use hook_menu to create your custom endpoint URL, which calls a callback function where you can define the output you want
function YOURMODULE_menu() {
$items = array();
$items['api/order'] = array(
'title' => 'API Orders',
'page callback' => 'YOURMODULE_api_orders_callback',
'access arguments' => array('access content')
);
$items['api/order/%'] = array(
'title' => 'API Orders',
'page callback' => 'YOURMODULE_api_orders_callback',
'page arguments' => array(2),
'access arguments' => array('access content')
);
return $items;
}
function YOURMODULE_api_orders_callback($order_id = NULL) {
$order_ids = array();
if(!is_null($order)) {
array_push($order_ids, $order_id);
}
// Load all orders or only 1 order
// We can use commerce_order_load_multiple()
// or use EntityFieldQuery() if need a complex logic filtering orders
$orders = commerce_order_load_multiple($order_ids);
drupal_json_output($orders);
}
The last solution is to use Services modules, create a custom module and create your custom service where you can define your custom resource - in this case - commerce_order.
A tutorial to create custom services can be found here 👉https://valuebound.com/resources/blog/how-to-create-custom-web-services-for-drupal-7-0
Let's say I have custom module with Drupal.
I want to let user to type what skill their have in first form and after that show their skill as a title in second form and type percentage of their skill in textfield.
function skillbar_form($form, &$form_state) {
$form['html5'] = array(
'#type' => 'textfield',
'#title' => t('HTML5'),
'#default_value' => variable_get('html5'),
'#description' => t('Enter a percent of your HTML5 skill'),
);
return(system_settings_form($form));
}
Multistep Form is you friend, if you are building your form using the Form API.
Otherwise there are various modules which could help you in building forms with more than one step. A couple of them being:
Multi-step forms
Multi-Step Registration
Note: Multistep forms generally collect all the data from various steps. The data is mostly submitted at the final step (which is also a best practice).
You can pass the data from one form to another through URL in the submit form of first form.
function skillbar_form_submit($form, &$form_state){
$data_a = $form_state['values']['html5'];
$form_state['redirect'] = array('url_page2', $data_a);
}
In the other form just retrieve the data as by passing the $data_a as argument. So $var will have the value as 'html5'.
example_form($form ,&$form_state, $var){
...
}
And for the URL you will have to send it in items array
$items['url_page2/%'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('page2_form', 1),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
I'm not really sure what direction to go in.
I have a box on multiple pages that displays the status of various items. I want it easily update-able and would prefer it to be updated via a module. I'm not sure what direction to go in and just need a gentle push.
I have created a table in the drupal sql db but not sure how I would go about creating an admin tool in the drupal control panel to make changes to it.
Does anyone have any ideas of how I should go about this?
p.s. I'm using drupal 7
Custom admin pages can be defined as follows:
function mymodule_menu() {
$items['admin/def'] = array(
'page callback' => 'mymodule_abc_view',
'page arguments' => array(1, 'foo'),
'access arguments' => array('administer nodes'),
'title' => 'Foo settings',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
Where mymodule is the name of your module and mymodule_abc_view is the function that returns the markup for your admin page
This is for the DRUPAL ninjas:
I am creating a menu_hook for my custom module called testmodule;
I want to call a MENU_CALLBACK and return a loaded CCK object of a custom content type I created called "VideoNodes"
example:
$items['save_video_data/%my_custom_cck_type/%'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'save_data_to_db',
'access arguments' => array('Save Data to my_custom_cck_type'),
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'title' => 'Save a Data!'
);
Now, with the above code, my understanding is that I am telling drupal to load my_custom_cck_type and use the array(2) position (my argument) as the id field of the node to find it in the database.
I also understand that, I am going to need to create a my_custom_cck_type_load() function.
QUESTION:
What shoudl be in my_custom_cck_type_load()?? How shall I grab all of the custom fields associated with the CCK type into the returned object? Or does drupal do this for me?
I'll use node_load as an example for this. Out of the box Drupal's menu system will load nodes at paths like.
node/1/view
node/2/view
node/3/view
(note: the "/view" part of the path is often hidden because it's the default tab)
The menu item setup to do this looks something like:
$items['node/%node/view'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => 'blabla',
'page callback' => 'node_view',
'page arguments' => array(1)
/* more stuff */
);
In the real path the %node is replaced by a number, the NID of the node. This will cause menu to fire node_load using that number as the argument. We're also using %node as the page argument for the node_view callback. The argument that callback receives will be the fully loaded node object.
In a Drupal multilingual site, for custom modules, (not nodes) what is approach to assure
that user navigates to same page in new language?
example: en/mypage to de/mypage
edit:
menu hook looks like this:
// add menu item
$items['my_module_name'] = array(
'title' => t('My Page Title'),
'menu_name' => 'menu-my-menu',
'page callback' => 'call_this_function_below',
'access arguments' => array('access content'),
);
You mean how to program a module with multilanguage support? Well, I would say you use a placeholder in the menu path you are registering your module for (hook_menu). In that way your module will get the request no matter what language identifier is used, so it will react for en/mypage as well as de/mypage. Of course in your module you must add custom processing logic to deliver the content in the requested language.