This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Redirect to a different page/URL based on form results
Started 17 years ago by mpivon | 4 posts |
-
Hi,
For those of you that don't know about the custom hooks function, I highly recommend using this to build out your forms with custom functionality.
Many of you have asked about redirecting forms based on user responses. This is one hook that you can add to the file "custom_hooks.php" that will accomplish this:
You can copy and paste the code below and just modify the variables as instructed.
// Substitute the form number for XXX and the element number for YYY
// the element number is the form segement that receives information from a user when a
// form is live.function formXXX_hook_post_validation($user_input){
$status = $user_input['element_YYY'];// In the statement below, the letter 'Z' needs to be replaced by the value of the
// element. But this can be tricky because radio forms and checkboxes often return
// a value like a 1 or a 2. Make sure you know the value, and
// don't confuse this with the form or element 'label'.if (strcasecmp($status,"Z") != 0)
{
// HERE'S THE MONEY STATEMENT
// This is the redirect to a webpage - OR another APPFORM that the user fills out
// This example illustrates a redirect to a Machform.$status = "http://www.ANOTHERWEBSITE.com/MACHFORM/view.php?id=6";
header ("Location: $status");
}else{
$status = true;
}return $status;
}Note that you must also insert a bit of code into one of the other pages, to make sure this hook is called when the form is loaded. (See the next post from me...)
Posted 17 years ago # -
IMPORTANT FYI: To do this you will need to ALSO modify includes/post-functions.php, insert the code below into line 772, above the query line.
//post_validation hook
if(function_exists("form{$form_id}_hook_post_validation")){
$result = call_user_func("form{$form_id}_hook_post_validation",$user_input);
if($result !== true){
$process_result['custom_error'] = $result;
}
}Posted 17 years ago # -
Thanks for sharing this!
I've marked this topic as sticky, for easy reference.
If anyone has useful customization like this one, please feel free to post it.MachForm Founder
Posted 17 years ago # -
hi mpivon,can you do a function that will display a some parts of a form initially blocked from display using an if else statement
Posted 15 years ago #
Reply
You must log in to post.