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

Conditional redirect url


  1. jflatham
    Member

    I live in Texas, but have moved to the state of "confusion." :-)

    I have a simple form containing several fields for facility reservation or cancellation. http://clearcreek13.org/testform_reservations02.php (form id=2)

    I have two radio buttons for facility choice and a check box for cancellation, among other data input. Depending on the selection, I wish to redirect to one of 3 URL's, one for each facility reservation (without cancellation checked) and one for cancellations, regardless of facility.

    What confuses me is whether this requires redirection and passing varibles to a script to process the redirection further, or can this be accomplished though modifying post-functions.php, among other MachForm files.

    While we are on this subject, when passing variables from radio buttons and checkboxes, what "values" are actually passed: 1,2,null,true,false, etc? In the case of 1 or 2, are these values integer or numbers or are they actually passed as text?

    Sorry for rambling!

    Posted 15 years ago #
  2. redityo

    Hi,

    You'll have a number value from check box and radio buttons, anyway for conditional redirect it's possible by edit your "post-functions.php" file. Go to around line 876 and you will see this code :

    $process_result['error_elements'] = $error_elements;

    You can put these code bellow that line and since you've form id = 2, with radio button id = 5 and check box id = 7 so the code will be like this :

    if ($form_id == 2)
    {
    	if ($table_data['element_7_1'] == '1') {
    		//cancelation
    		$process_result['form_redirect'] = "http://www.cancel.com";
    	}
    	else {
    		if ($table_data['element_5'] == '1')
    			$process_result['form_redirect'] = "http://www.first.com";
    		elseif ($table_data['element_5'] == '2')
    			$process_result['form_redirect'] = "http://www.second.com";
    	}
    }

    Change the url with your requirement, I hope you can move to texas again with this :)


    MachForm Support

    Posted 15 years ago #
  3. jflatham
    Member

    Thanks bunches! Last question: In the form properties for Form 2, for the redirect URL, should I leave it blank or just put in one of the actual URL's?

    Posted 15 years ago #
  4. yuniar

    You can put one of them, or any URL would do.


    MachForm Founder

    Posted 15 years ago #
  5. jflatham
    Member

    I have completely tested the post-functions.php edits suggested by Redityo. It worked like and absolute charm. Thanks for all the great assistance!

    Posted 15 years ago #
  6. roguevoice
    Member

    Tried the above, however it seems not to work with form review enabled.

    Posted 14 years ago #
  7. redityo

    If you have review page feature enabled, you should add some code in your "post-functions.php" again :) . To do so you need to update my previous code from :

    if ($form_id == 2)
    {
    	if ($table_data['element_7_1'] == '1') {
    		//cancelation
    		$process_result['form_redirect'] = "http://www.cancel.com";
    	}
    	else {
    		if ($table_data['element_5'] == '1')
    			$process_result['form_redirect'] = "http://www.first.com";
    		elseif ($table_data['element_5'] == '2')
    			$process_result['form_redirect'] = "http://www.second.com";
    	}
    }

    to be like this

    unset($_SESSION['form_redirect']);
    if ($form_id == 2)
    {
    	if ($table_data['element_17_1'] == '1') {
    		//cancelation
    		$process_result['form_redirect'] = "http://www.cancel.com";
    	}
    	else {
    		if ($table_data['element_5'] == '1')
    			$process_result['form_redirect'] = "http://www.first.com";
    		elseif ($table_data['element_5'] == '2')
    			$process_result['form_redirect'] = "http://www.second.com";
    	}
    }
    
    if (!empty($process_result['form_redirect']) && $process_result['form_redirect'] != '') {
    	$_SESSION['form_redirect'] = $process_result['form_redirect'];
    }

    after that go to around line 2189, you will see this code :

    $esr_plain_text	= $row['esr_plain_text'];

    add this code exactly bellow that line :

    if (!empty($_SESSION['form_redirect']))
    	$form_redirect = $_SESSION['form_redirect'];

    MachForm Support

    Posted 14 years ago #
  8. roguevoice
    Member

    Thanks. Will try now and report back.

    Posted 14 years ago #
  9. roguevoice
    Member

    Worked perfectly. Thanks for the quick support. Great product. Is the data stored in a table to build HTML forms dynamically?

    Posted 14 years ago #
  10. redityo

    Yes.. machform save form submission and form data to database.


    MachForm Support

    Posted 14 years ago #
  11. aolmos
    Member

    Hi!
    I use machform 2, and I can't locate that $process_result['error_elements'] = $error_elements; text in the post-functions.php file. Please tell me how to do it in machform 2. It is urgent! :-(

    Thank you

    Posted 11 years ago #
  12. yuniar

    It should be located around line 876. Make sure to use text editor which has line numbers.


    MachForm Founder

    Posted 11 years ago #
  13. manzoorahmed
    Member

    Hi,

    Is this code still valid for 4.5?
    It doesn't seem to work for me.

    Regards,

    Posted 8 years ago #
  14. williamansley
    Member

    @manzoorahmed: I would recommend against trying the methods given in this discussion; I doubt they would work now. since Machform has changed a lot in the last three to six years. If you want to redirect the user to one of several different web pages, based on the form input, you can now do this with the "Logic Builder", using the "Enable Rules to Display Success Page" option, without modifying any code! If you need more help with this, please respond, and I'll do my best to supply more details.

    Posted 8 years ago #
  15. manzoorahmed
    Member

    Thank you @williamansle

    For this I have to update to 4.7. I will do that and let you know if there is any issue.

    Regards,

    Manzoor

    Posted 8 years ago #

RSS feed for this topic

Reply