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

Dropdown Links


  1. reprocessor
    Member

    Hi all,

    I was wondering if you can make the options in a dropdown list link to another page. For example; there'd be 20 trades in the dropdown and when you select one and click submit it will take you to the appropriate page for that trade. I've seen the post that will allow you to do this for email (I think it was Anthony Best's post - on the sticky list) and would like to know how to do it for links as my php aint that good ;)

    Cheers,

    Phil

    Posted 15 years ago #
  2. yuniar

    Hi Phil,

    Pretty simple actually. Let's take an example with this form:
    http://www.appnitro.com/forms/view.php?id=19

    That form is having form_id = 19 and the "Redirect To" dropdown is having id = "element_2" (view the HTML source to see this)

    The dropdown is having some values:

    <option value="1" >Google</option>
    <option value="2" >Yahoo</option>
    <option value="3" >MSN</option>

    Now, the plan is to redirect to either Google or Yahoo or MSN, based on the selected dropdown.

    Edit your includes/post-functions.php file, around line 1173 - 1175 you'll find this code:

    if(!empty($form_review)){
    	$process_result['review_id']   = $record_insert_id;
    }

    Exactly below the above code, add this code:

    if($form_id == 19){
    	switch ($user_input['element_2']){
    		case 1 : $redirect = 'http://www.google.com'; break;
    		case 2 : $redirect = 'http://www.yahoo.com'; break;
    		case 3 : $redirect = 'http://www.msn.com'; break;
    	}
    
    	$process_result['form_redirect'] = $redirect;
    }

    That would do it.

    Of course, you will need to adjust the above code with your own values.

    Note: The code above only work for form with "Form Review" disabled.


    MachForm Founder

    Posted 15 years ago #
  3. reprocessor
    Member

    Thanks for this Yuinar - I'll give it a try soon and will let you know how i get on :)

    Cheers,

    Phil

    Posted 15 years ago #
  4. reprocessor
    Member

    Thanks Yuniar - this worked a treat ;)

    Best regards,

    Phil

    Posted 15 years ago #
  5. drumaboy46
    Member

    I am trying to achieve the same thing but I have two elements that it could be for example. I want to redirect users to the right custom paypal page based on what they select so when they review their submission and hit submit the entry is received and they are taken to the proper URL. Based on the example above this is what I have but it just shows the confirmation page after submission.

    My Code:

    if($form_id == 7) {
    	switch ($user_input['element_14']) {
    		case 1 : $redirect = 'customURL'; break;
    		case 2 : $redirect = 'customURL'; break;
    	}
    	switch ($user_input['element_15']) {
    		case 1 : $redirect = 'customURL'; break;
    		case 2 : $redirect = 'customURL'; break;
    	}
    	$process_result['form_redirect'] = $redirect;
    }

    what am I doing wrong?

    Posted 13 years ago #
  6. redityo

    I think you've enable the form review, the above code only work if the form review is disabled. However, you can customize the code to works with form review enabled. Try to follow these steps :

    1. Change this line

    $process_result['form_redirect'] = $redirect;

    into

    $process_result['form_redirect'] = $redirect;
    $_SESSION['form_redirect'] = $process_result['form_redirect'];

    2. Go to around line 2337 in "post-functions.php" file for this code:

    $commit_result['form_redirect'] = $form_redirect;

    and put these code exactly bellow that line

    if (!empty($_SESSION['form_redirect'])) {
    	$commit_result['form_redirect'] = $_SESSION['form_redirect'];
    	unset($_SESSION['form_redirect']);
    }

    MachForm Support

    Posted 13 years ago #
  7. drumaboy46
    Member

    fantastic!!!!!! works like a charm. One small thing though I want a success message to show for about 5secs like in this example:

    http://www.appnitro.com/forums/topic/redirect-after-submission?replies=8

    but how do I pass my custom URLS's to the view-functions.php since I have multiple redirects that are possible?

    Posted 13 years ago #
  8. redityo

    It's possible but you need to change the previous code also. Try to follow these steps :

    1. Change these from previous code :

    if (!empty($_SESSION['form_redirect'])) {
    	$commit_result['form_redirect'] = $_SESSION['form_redirect'];
    	unset($_SESSION['form_redirect']);
    }

    to

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

    2. And Refer to this post

    http://www.appnitro.com/forums/topic/redirect-after-submission?replies=8

    You can change this code :

    if ($form_id == 1) {
    	$custom_redirect_url = '<meta http-equiv="Refresh" content="5;url=http://www.domain.com">';
    }

    into

    if ($form_id == 1 && !empty($_SESSION['form_redirect'])) {
    	$custom_redirect_url = '<meta http-equiv="Refresh" content="5;url='.$_SESSION['form_redirect'].'">';
    	unset($_SESSION['form_redirect']);
    }

    MachForm Support

    Posted 13 years ago #
  9. drumaboy46
    Member

    still not showing the success page just redirecting to paypal.

    here's what I have:

    post-functions.php around line 1186

    //CUSTOM CODE REDIRECT/////////////////////////////////////////////////
    if($form_id == "7") {
    	switch ($user_input['element_14']) {
    		case 1 : $redirect = "customURL"; break;
    		case 2 : $redirect = "customURL2"; break;
    	}
    	switch ($user_input['element_15']) {
    		case 1 : $redirect = "customURL3"; break;
    		case 2 : $redirect = "customURL4"; break;
    	}
    	$process_result['form_redirect'] = $redirect;
    	$_SESSION['form_redirect'] = $process_result['form_redirect'];
    }

    bottom of page in post-functions.php

    $commit_result['form_redirect'] = $form_redirect;
    //CUSTOM REDIRECT CODE////////
    if (!empty($_SESSION['form_redirect'])) {
    	$commit_result['form_redirect'] = $_SESSION['form_redirect'];
    }
    return $commit_result;
    ////////////////////////

    and lastly view-functions.php around line 2228

    if ($form_id == 7 && !empty($_SESSION['form_redirect'])) {
    
    $custom_redirect_url = '<meta http-equiv="Refresh" content="5;  url='.$_SESSION['form_redirect'].'">';
    
    unset($_SESSION['form_redirect']);
     }

    THANK YOU FOR ALL YOUR HELP you rock. Just to be clear though all I want is when they review there inpu and click submit to be taken to the success page where it say "Success your submission...." then I want them to be redirected. :D

    Posted 13 years ago #
  10. drumaboy46
    Member

    ok tried everything still can't get the success page to show before redirecting.

    Posted 13 years ago #
  11. yuniar

    Hmm... is it possible for us to try your form?
    Let us know the URL please.

    You can send it via email: customer.service [at] appnitro.com
    Also, send us the modified files as well (view-functions.php and post-functions.php)


    MachForm Founder

    Posted 13 years ago #

RSS feed for this topic

Reply