Hey all. My form is playing some strange tricks on me, and I wanted to run this by you guys to see if this is a problem anyone else has had before, or if I just need to keep checking my code for bugs.
I call drupal_get_form on a function called gradprofile_edit_profile. Instead of just building the form in this function, I check a student type that was passed in to gradprofile_edit_profile and call one of two other functions that returns a form customized to the type of student that is passed in, like this.
function gradprofile_edit_profile($csid, $show_status = false) {
$new_student = new GradStudent($csid);
$new_student->populate_student_from_database();
if ($new_student->student_type == 'Masters') {
return _get_masters_profile_edit_form($new_student, $show_status);
}
else if ($new_student->student_type == 'PhD') {
return _get_phd_profile_edit_form($new_student, $show_status);
}
}
My submit button generated by the form does not work anymore. It just reloads the page, but no validation is done, and the values are not submitted. I make sure to check wether it is a PhD or Masters form in gradprofile_edit_profile_submit, but I went the code through with a debugger and this function is never called. Is this because of how I am generating my form, eg by not just building it in gradprofile_edit_profile, or is it my own dumb fault somewhere else in the code?
Much obliged -
Jergason
Comments
Update: $_POST['form_id'] is null
So I stepped through with a debugger again, and ended up all the way in drupal_process_form, where I discoverd that the POST form_id variable is not set. That is supposed to be set when the user clicks the submit button, but it is not happening, and thus the calls to drupal_validate_form and drupal_submit_form are skipped. I still don't know why POST['form_id'] is not being set.
Can anyone point me in a direction to investigate this more in-depth?
UPDATE: problem was in theme funciton
Okay, now I am just documenting my problem for future reference. My theme function renders each element in the form individually, and ends with a call to drupal_render($form['submit']). Apparently, there are some other hidden values that need to be rendered with the form as well. When I call drupal_render($form) at the end of my theme function, some elements are repeated, but the validate and submit functions get called finally. Still working on figuring this out.
Did you ever figure this out
Did you ever figure this out I think i'm having the same problem
Yeah, I just had to make sure
Yeah, I just had to make sure I was calling
drupal_render($form)at the end of my theme function.