By carlogen on
Hi all,
I am trying to find out how forms are working in Drupal.
I actually need to create a form that when it is submitted redirect the values to an external link.
I am am able to do it with an html/php, But i do not know how to do it with Drupal.
I attach below both codes.
I will really appreciate anyone could point me in the right direction, even with an URL for a documentation. I looked in form API doc but probably I do not have the knowledge yet to understand it.
I am trying to learn.
Thanks to evryone
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<html>
<body>
<form id="tm_quicksearch" action="flight-results" method="post" target="_top">
<input id="site_ident" type="hidden" name="site_ident" value="test"/>
<input id="submit" type="hidden" name="submit" value="1"/>
<select id="fromcity" class="selectbox" name="fromcity">
<option value="NY">NY</option>
....
</select>
<select id="dest_city" class="selectbox" name="dest_city">
<option value="LV">LV</option>
....
</select>
<input id="return_flight" type="radio" value="0" name="oneway" checked="true" />Ritorno
<input id="oneway" type="radio" value="1" name="oneway">Solo andata
<select id="oday" class="selectbox" name="oday">
<option value="01">01</option>
....
</select>
<select id="omonth" class="selectbox" name="omonth">
<option value="6-2009" selected="true">Giu 2009</option>
...
</select>
<input type="submit" text="cerca"/>
</form>
<?php
$form['contact'] = array(
'#type' => 'fieldset',
'#title' => t('Contact settings'),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
?>
</body>
</html>
file flight-results
<html>
<body>
<?php
$site_ident = $_POST['site_ident'];
$dbemode = $_POST['dbemode'];
$dosearch = $_POST['dosearch'];
$submit = $_POST['submit'];
$fromcity = $_POST['fromcity'];
$dest_city = $_POST['dest_city'];
$oneway = $_POST['oneway'];
$oday = $_POST['oday'];
$omonth = $_POST['omonth'];
$site = "example.org?";
// form processing code
?>
<iframe src =
<?php
print "$site";
print"site_ident=$site_ident&";
print"dbemode=$dbemode&";
print"dosearch=$dosearch&";
print"fromcity=$fromcity&";
print"submit=$submit&";
print"dest_city=$dest_city&";
print"oneway=$oneway&";
print"oday=$oday&";
print"omonth=$omonth";
?>
width="100%" height="2000" frameborder="0" scrolling="auto">
</iframe>
</body>
</html>
my Drupal form
<?php
function travelsearch_menu() {
$items['travelsearch'] = array(
'title' => 'ricerca Volo',
'page callback' => 'travelsearch_page',
'access arguments' => array('access content'),
);
return $items;
}
function travelsearch_page() {
$output = t('This page contains our example form.');
$output .= drupal_get_form('travelsearch_nameform');
return $output;
}
function travelsearch_nameform() {
$form['dest_city'] = array(
'#title' => t('aeroporto arrivo'),
'#type' => 'textfield',
'#description' => t('inserire aeroporto di arrivo'),
);
$form['oneway'] = array(
'#type' => 'radios',
'#title' => t('andata e ritorno'),
'#options' => array(
'1' => t('solo andata'),
'0' => t('ritono.'),
),
'#description' => t('seleziona andata e ritorno'),
);
$form['data_partenza'] = array(
'#type' => 'date',
'#title' => t('data partenza')
);
$form['data_ritorno'] = array(
'#type' => 'date',
'#title' => t('data ritorno')
);
$form['#method'] = 'post';
$form['#action'] = 'http://www.example.org';
$form['#attributes'] = array(
'enctype' => 'multipart/form-data',
'target' => 'top'
);
$form['#prefix'] = '<div class="my-form-class">';
$form['#suffix'] = '</div>';
// tasto ricerca
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search')
);
return $form;
}
?>