Hi-
given the following code:
...
$evalCase = returnYesOrNo();
if ($evalCase) {
foo();
} else {
bar();
}
In the above example, I want returnYesOrNo() to present a form where the user can say Yes or No, much like a confirmation delete dialog. If the user clicks yes, I want a TRUE returned to $evalCase, if no, a FALSE returned.
The way I understand form buttons, they must point to a form_submit callback, and from there, any arbitrary code you instruct the form_submit_callback to execute executes.
I guess what I want is the form_submit_callback to return a value to the $evalCase var. Is that possible? Or do I just need to structure my code so that the last thing it does is render the form, and the submit calls one of two different callbacks which accomplish what I want?
thanks,
geremy
Comments
Forms API Quickstart Guide
Please have a look at the Forms API Quickstart Guide.
Hi- Thanks for the advice.
Hi-
Thanks for the advice. I may have overlooked something. #4 towards the bottom indicates:
"To determine where the user should be sent after the form is processed, the _submit function can place a path or URL in $form_state['redirect'] which will be the target of a drupal_goto; every form is redirected after a submit. If you store nothing in $form_state['redirect'], the form will simply be redirected to itself after a submit. It is polite to use drupal_set_message() to explain to the user that the submission was successful."
So basically, according to this, there is no way to accomplish what I'm trying to do? I don't want to redirect to another URL, I want to return to a calling function with a value.
thanks,
geremy
Confusing
What you are saying does not really make sense.
What do you mean return to a calling function. The end result of all page calls or form submits, the very end result, is the display of a page. This 'function' you speak of is your form submit function.
im convinced its not possible
Instead of having a form submit call a new page upon completion, I wanted to know if I could have it issue a return instead.
That way, I could do this:
$status = drupal_get_form_return(YesOrNoForm);
if ($status == 'no')
...
else
...
So, in this code snippet, $status is populated by a return value returned from the YesOrNoForm submit function. I make decisions through the rest of the code based on what this form returned. I think it just wont work like this, just wanted to know if I was overlooking something.
You make your decisions in
You make your decisions in the submit function. If you need to set a value that persists to be picked up somewhere else, then use drupal persistent variables and the drupal_set_variable and drupal_get_variable set of functions and you can pass whatever you need around.
thank you for your advice,
thank you for your advice, will try.
geremy