I'm looking for ideas here...

I'm revisiting the code to the Ubercart checkout form which you can get to through the "work-in-progress" site at http://livetest.ubercart.org. On the checkout page is a Cancel button that takes the user back to the cart view page. The checkout screen naturally has some required fields to collect customer information.

Now, with a Cancel button, you obviously don't care if the customer has filled out all the required fields. I could just do a switch on $form_values['op'] and if I see t('Cancel') then I send them back to the cart screen. However, it has to go through validation before it ever gets to the submit function, so in validation it's throwing up a bunch of errors for those incomplete fields. This just won't do...

So, I used simple Javascript in that form to put ('onclick' => 'window.location = '. base_path() .'"cart"; return false;') in the attributes. That'll kick us out to where we want to go, and in other places also I've used return false; to keep a form from submitting. The question I have is... what in the world can I do for users who aren't using Javascript? (In this situation and others.)

Is there a way to keep the FAPI from trying to validate these required fields? Right now the button type is useless in FAPI, and I'm not sure that '#submit' => FALSE does anything either.

Up for suggestions or questions if I need to clarify anything here...

Comments

chx’s picture

do a check in your form building function for $_POST['op'] and drupal_goto based on that. comparisons with $_POST are ok, storing / displaying is not that ok :)
--
The news is Now Public | Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

rszrama’s picture

Excellent idea. Thank you very much!

Would it be helpful to roll a patch that adds this functionality? Basically, there's the #submit attribute for form elements that sits dormant... I really don't see where that gets considered in the code at all. I can imagine this attribute being used to bypass validation, but you'd still want it to call the submit hook (so this solution seems counter-intuitive...). I don't know a better way to handle that.

Perhaps if #submit is FALSE or #type is button, it just won't do the required field check? That seems like a good solution to me... any thoughts?

(On that note, it seems smart to roll a patch that changes an element of #type button to actually display buttons...)

yogitha’s picture

('onclick' => 'window.location = '. base_path() .'; return false;')
how to close the session along with this do u have any idea?
I need a cancel button along with session_destroy() and redirect to base_path()