0
votes

I have content type booking and created booking page in drupal 7 and same page is displaying error, confirmation and booking page. I am trying to split into three different pages(nodes) using same booking content type. I am using custom module for booking.

After booking, I would like to redirect to xyz.com/booking-confirm if it's successfully booking and if it's error xyz.com/booking-error and currently, using xyz.com/booking for all actions.

Should I use header to redirect it?

header('Location: /booking-confirm'); 
header('Location: /booking-error'); 

Should I hook them in template.php?

function MYMODULE_user_register_form($form, &$form_state) {
  $form_state['redirect'] = 'path/to/somewhere';
}

I am not sure, which is correct option to figure it out. I would like to split the URL using same content type. Any approach to solve the issue.

1

1 Answers

1
votes

Leave the template and headers out of it.

Use hooks hook_FORM_validate() and hook_form_submit in your custom module:

Example for form_submit:

function your_booking_form_submit(&$form, &$form_state) {
$form_state['redirect'] = '/thank-you-page';
}

function your_booking_form_validate($form, &$form_state) {
// if criteria is not met (user entered wrong data or whatever the validation you do) {
$form_state['redirect'] = '/error-page';
}
}