By I am learning on
A hypothetical example:
user comes to http://www.mywebsite/result first time and he sees a form there, he clicks Yes or No whatever, after the form submit he comes back to the same URL. Now if he clicked Yes earlier, show the form again else do not show the form.
Hook Menu
function search_result_menu() {
$items = array();
$items['result'] = array(
'title' => 'View Summary Result',
'description' => 'View Result',
'page callback' => 'search_result_display',
'access arguments' => array('View Result'),
'type' => MENU_CALLBACK,
);
return $items;
}
This displays the page content that creates a form
function search_result_display() {
...
//create the form
if($show_form_again) {
drupal_get_form('confirmation_form');
}
..
}
Create a form with just Yes No buttons
function confirmation_form() {
$form['fieldset']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Yes'),
);
$form['fieldset']['submit'] = array(
'#type' => 'submit',
'#value' => t('No')
);
return $form;
}
Check what was clicked by the user and set a variable's value;
function confirmation_form_submit($form, &$form_state) {
if($form_state['values']['op'] == t('Yes')) {
$show_form_again=true;
} elseif($form_state['values']['op'] == t('No')) {
$show_form_again=false;
}
}
I don't know if I am sounding stupid but my requirement is complex so instead of writing so much I've given this hypothetical example to understand this implementation.
Thanks and Regards
Comments
Now if he clicked Yes
How much earlier? Any time in the past? Or you mean while on the same page?
Contact me to contract me for D7 -> D10/11 migrations.
Just the last time in the
while on the same page, should I use session variables? or Drupal has another way to handle such things?
Yep: <?php//form
Yep:
if $form_state['storage'] is set, the form will automatically be rebuilt. The value I saved to it was entirely arbitrary, just to show an example.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks Jay, unfortunately in
Thanks Jay, unfortunately in both the cases the form is appearing, I simply added
in if else respectively.
Sorry, I wasn't really
Sorry, I wasn't really thinking. Your original form definition should be:
Your submit function should be as is.
Contact me to contract me for D7 -> D10/11 migrations.
Thank you so much. Regards
Thank you so much.
Regards