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

Custom Redirect URL using value from hidden field


  1. JugglerX
    Member

    I am trying to specify the custom redirect URL using the value of a hidden field in my form. the field is {element_10}

    I had a look through the code and tried ['form_redirect'] = '{element_10}' but that did not work. I think you can see what I'm trying to achieve but I don't know the correct code.

    Posted 15 years ago #
  2. redityo

    Hi,

    To do that you need to edit "includes/post-functions.php" file, go to around line 953 ~ 954 and you will see these code :

    //add session_id to query if 'form review' enabled
    if(!empty($form_review)){

    put these code exactly above that line

    if (!empty($table_data['element_10'])  && $form_id == '5') {
    	$process_result['form_redirect'] = $table_data['element_10'];
    }

    In there i assume your form id is 5, don't forget to change the ID's with yours. Anyway to hide the field you can add these code in CSS form

    #li_10
    {
    display:none !important;
    }

    MachForm Support

    Posted 15 years ago #
  3. RonPacheco
    Member

    I needed to do almost this same exact thing, but I needed a more general and permanent solution. I solved this by adding the ability to have the redirect string include form fields. E.g., my redirect string for the form on the form properties page is specified something like this:

    http://my.site.com/page.php?x="{element_1}"&y="{element_12}"

    When the form is submitted, the proper fields from the form submission are substituted into the URL.

    Here's the code block that accomplishes this. It should be inserted into the "includes/post-function.php" file in the same position as the solution proposed above.

    // perform input field substitutions on redirect url
    while ( preg_match( '/\{(element_\d+)\}/', $process_result['form_redirect'], $matches ) > 0 ) {
      if ( !empty( $table_data[$matches[1]] ) ) {
        $process_result['form_redirect'] =
          str_replace( $matches[0], urlencode( $table_data[$matches[1]] ), $process_result['form_redirect'] );
      }
      else {
        $form_redirect = str_replace( $matches[0], '', $form_redirect );
      }
    }

    Just thought I would share since this is a great little app and I found this small enhancement to be quite powerful!

    Posted 14 years ago #
  4. moonlightss
    Member

    Hi RonPacheco,

    Great tip. I was looking for something exactly like this. However, i do have one question. When i pass an element like this {element_1_1} it fails to do the replacement. I change '/\{(element_\d+)\}/' to this '/\{(element_\d+_d+)\}/' and it works for the {element_1_1} replacement, but not the {element_1} replacement. Not much on this particular function of matching. is there any way to catch both?

    Thanks.

    Posted 14 years ago #

RSS feed for this topic

Reply