By Lebby on
Hi all! It's my first post here!
I've a block (created by mine module ) that contains a form created by same module. ( we'll call this form: form1)
I've another form that is created by drupal interface ( is a node/content_type/add form ). ( we'll call this form: form2 )
I want that when i click "submit" button, all parameters from form1 go to form2 and form2 is loaded in main content.
I don't know how to pass parameter and load form2 ... I've implemented form_alter and it is called :D
my "example core" code:
<?php
function ecustom_form1_form() // modulename_formname_form = module_hook_form()
{
if (node_access('update', $node))
{
if(!function_exists('node_form'))
{
module_load_include('inc', 'node', 'node.pages');
}
}
return drupal_get_form('form1_form');
}
function form1_form($form_state) // formname_form = hook_form()
{
$form['field1'] = array(
'#type' => 'textfield',
'#title' => t('field1'),
'#required' => TRUE,
'#size' => 30, // added
'#autocomplete_path' => 'taxonomy/autocomplete/field1',
);
$form['field2'] = array(
'#type' => 'textfield',
'#title' => t('field2'),
'#required' => TRUE,
'#size' => 30, // added
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
// '#submit' => array('form2_send'), // if i want to customiza submit function = submit callback
);
return $form;
}
function form1_form_submit($form, &$form_state) // formname_form_submit = module_hook_form_submit()
{
drupal_set_message(t('The form has been submitted.'));
// now here i want to load form2 passing $form_state that contains all value in input field :) ... how?
}
function ecustom_form_alter(&$form, &$form_state, $form_id) // modulename_form_alter = hook_form_alter()
{
if($form['form_id']["#value"] == 'form1_node_form') {
//modify form1 ... i think no needed
}
if($form['form_id']["#value"] == 'form2_node_form') {
//modify form2 ... = assign #default_value and disable if is possible
}
return $form;
}
//bonus code ... load a form in a block
function ecustom_block_info() {
$blocks['form1_block'] = array(
'info' => t('form1 block title'),
'cache' => DRUPAL_CACHE_PER_ROLE, //Default
);
return $blocks;
}
function ecustom_block_view($delta = '') {
switch ($delta) {
case 'form1_block':
$block['content'] = drupal_get_form('form1_form');
break;
}
return $block;
}
?>Am i doing all right? Am i missing or doing something wrong? ( exclude my english ... :) )
Comments
How about something like
How about something like this, in form1_form_submit() where the comment is
And then in ecustom_form_alter() you can get the values with $_GET['field1'] and $_GET['field2']
Before I want to say tnx! but doesn't work
Before I want to say tnx! Drupal community is nice and very collaborative! I'm trying to give mine contrib!
... it doesn't work ... When i print by dpm($_GET) i have only q => node/add/content_type.
Typo on my part, I fixed the
Typo on my part, I fixed the post above
Tnx! it works!
It works.
There are alternative way to pass data?
Can i pass that values by POST method? Is it too complicated?
When I need this kind of
When I need this kind of functionality I this is the method I use