By ianfoxfire on
So i have created a form with drupals form api, and now want to pass the values to another page, in wich I hope to retrieve these values via $_POST. IS THIS POSSIBLE? and if so, can you point me to an example?
Form Page:
<?php
$f = drupal_get_form('my_search_form');
print $f;
function my_search_form(){
$form['myName'] = array(
'#type' => 'textfield',
'#title' => 'My Name',
'#size' => 64,
'#maxlength' => 64,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
return $form;
}
function my_search_form_validate($form, &$form_state) {
if ($form_state['values']['myName'] == '') {
form_set_error('', t('Field Blank, please add something to search for.'));
}
}
function my_search_form_submit($form, &$form_state) {
$s = $form_state['values']['firstName'];
drupal_redirect_form($form, 'node/6');
}
Form Result Page (node/6):
<?php
if(isset($_POST)){
print_r($_POST);
}
?>
so far the results are "Array ( )"
Comments
Here you will not get any
Here you will not get any value. Because drupal_redirect_form($form, 'node/6'); will return get method so you will not get any thing in post.
This function will work similar as drupal_goto(). You have to find out some another solution like using session or etc...
Regards,
Vijay
Thanks,
Vijay Thummar
This is basically what I was
This is basically what I was looking to do, is there any other way other than using a session to do this? using sessions to pass form info feels a bit crude to me.
A work around would be to
A work around would be to NOT use drupals form API, simply make your form in php/html as your normally would. then as you pass data it will be available via _POST.
I put another post in the forum asking for someone to show me a simple example, where a form is submitted, then to display, what was submitted on the same or another page, and got NO answer. Unless your reading and writing this data to the database, somewhere I still dont have any idea how its possible. soooo, to get around the unfamiliar behavior of drupals Form API, i have just decided to reinvent the wheel a little, and create my own Form API, that does what I need. If your interested in using it, let me know, and Ill keep you posted with the progress. At this point, it functional but can only create forms with fieldsets, labels, input tags.
Otherwise, maybe you or someone can figure out how to get PEAR Quickform to work aside drupal no problem.. i didnt seem to have much luck.
good luck
Place the
Place the $form_state['values'] in a session variable.
That session will be available in next page pass the session to a variable and unset that session variable.
This how I came accross this problem..If you got any other solution please let me know...
to pavaniakella
I will try your solution, i am doing the same thing
- build a form (external search module)
- send a get url (search query) to an external server. By default this external search module redirect me to the external site's result page using durpal_goto()
- well, i do not want that. instead I want to get the html response parse it and print the formated response text to the form which i forgot to mention is a block module. If you try out the external serach module you will see clearly what i mean.
Thanks buddies!
D.
to pavaniakella
Ok, it works! thanks so much pavani akella
in the .module page:
function extesea_search_form_submit($form, &$form_state) {
$s = $form_state['values']['firstName'];
$values = $form_state['values'];
$block = $values['block'];
$engine = extesea_engine_load($values['engine']);
$keywords = empty($values['keywords']) ? '' : str_replace(' ', '+', $values['keywords']);
$location = str_replace('[extesea]', $keywords, $engine['url']);
if (isset($engine['fields'])) {
foreach ($engine['fields'] as $token => $field) {
if (count($block->engines) > 1) {
$replace = $block->engines[$values['engine']]['field_values'][$token]['default'];
}
else {
$replace = $values['field_' . $token];
}
$location = str_replace('[' . $token . ']', $replace, $location);
}
}
// this is to get the html source
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$location);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
dvm($values);
$_SESSION['views'] = $buffer;
drupal_redirect_form($form, 'node/6');
}
in drupal admin ui create a node/6:
I am still improving the implementation to write the result to the same search block so that we do no have to create a node/6 e.g. I will send all code to you if you need dunnleaddress@gmail.com
multi-page forms
I would use a multi-page or compound form, where the form redirects to itself upon submission. You can pass the values from the first stage to the second using the form API for hidden values or stored values (i.e., $form_state['storage']), either method will work, and if you start your form building function (i.e. hook_form) with an if-then to tell what stage of the form you are in, you can first render the form fields, then on the second stage just do the processing with the form submission data that you need to do, and finish with a redirect, without necessarily having rendering any new form elements in the second stage.