This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 3

Displaying form data on form confirmation/success PHP page


  1. ivycreekelementary
    Member

    Do the instructions noted within the post linked to below (which also includes a link to another post with more detail) work within MachForm 3?

    http://www.appnitro.com/forums/topic/referencing-input-data-in-the-redirect-thankshtm-page?replies=7#post-7400

    I have the following code entered within my MachForm 3.1 installation, but receive either a "You are not authorized" message or "Dear, Thank you for registering!" (the "Dear" is recognized, but no data is being pulled through) when submitted.php is loaded when the form is completed (i.e., either the data from the form isn't being allowed through or it's simply not going through at all).

    Within includes/post-functions.php, lines 4323-4327, there is already this:

    //if there is no error message or elements, send true as status
    
    if(empty($error_elements) && empty($process_result['custom_error'])){
    
    	$process_result['status'] = true; I added the referenced lines

    ...and I simply added the additional two lines beneath (lines 4328 and 4329) so that the updated listing is:

    //if there is no error message or elements, send true as status
    
    if(empty($error_elements) && empty($process_result['custom_error'])){
    
    	$process_result['status'] = true; I added the referenced lines
    	$_SESSION['is_valid_user'] = true;
    	$_SESSION['form_data'] = $table_data;

    Then, within my submitted.php file, I have the following:

    <?php 
    
    session_start();
    
    if($_SESSION['is_valid_user'] !== true){
    die("You are not authorized to see this page");
    }
    
    echo 'Dear '. $_SESSION['form_data']['element_2']; ?>
    , Thank you for registering!

    Any thoughts? Does the coding need to be any different with MachForm 3.1?

    So you know, I'm hoping to have some of the form data (such as their name, the date/time they submitted the form, etc.) appear on the form submission confirmation page so that the user can print that page and bring it with them to a meeting as proof they completed the online form.

    Thank you for your help!

    Joel

    Posted 12 years ago #
  2. ivycreekelementary
    Member

    Nevermind! 5 minutes after I posted the above message everything just started working properly. Go figure!

    Thanks for all the instructions, by the way!

    Posted 12 years ago #
  3. mjg234
    Member

    I have MF version 3.2. The file includes/post-functions.php has only 3,066 lines in it. Joel's original post references "lines 4323-4327" for this modification. This text looks like it appears at line #2204. Is just below this where I should add:
    $_SESSION['is_valid_user'] = true;
    $_SESSION['form_data'] = $table_data;

    Posted 12 years ago #
  4. ivycreekelementary
    Member

    mjg234,

    Yes, apparently the line numbers changed with the update from MachForm 3.1 to 3.2, and you're correct on the updated line number you noted.

    In MachForm 3.2, within includes/post-functions.php, lines 2204-2206 are:

    //if there is no error message or elements, send true as status
    		if(empty($error_elements) && empty($process_result['custom_error'])){
    			$process_result['status'] = true;

    Just beneath there (say, lines 2208-2209), the following should be placed (and everything should work as previously described):

    $_SESSION['is_valid_user'] = true;
    			$_SESSION['form_data'] = $table_data;
    Posted 11 years ago #
  5. ivycreekelementary
    Member

    FYI: In MachForm 3.3 the lines for the existing code (under which you should add the new code) have changed from 2204-2206 to 2254-2256.

    Posted 11 years ago #
  6. yuniar

    If you are using multi-page form, you need to add another code and use different session variable name. So, in addition to the above code, you will also need to edit "includes/post-functions.php" file, around line 2729 you should see this code:

    return $commit_result;

    exactly above that line of code, add this block:

    $entry_values = mf_get_entry_values($dbh,$form_id,$new_record_id);
    $_SESSION['form_data_multipage'] = $entry_values;
    $_SESSION['is_valid_user'] = true;

    this would store all the form data into $_SESSION['form_data_multipage'] variable.

    Now, to access the variable on the success page, you can do it like this:

    echo $_SESSION['form_data_multipage']['element_1']['default_value'];
    echo $_SESSION['form_data_multipage']['element_2']['default_value'];
    echo $_SESSION['form_data_multipage']['element_3']['default_value'];
    echo $_SESSION['form_data_multipage']['element_4']['default_value'];

    and so on.


    MachForm Founder

    Posted 11 years ago #
  7. ivycreekelementary
    Member

    Thank you very much, Yuniar. Works like a charm!

    The only thing I'd like to note is that on my PHP page, if I'm referencing form-specific data (i.e., fields that I've added within that specific form), I should indeed use the form_data_multipage option you noted within the PHP code on the confirmation page. However, with "general" form data (e.g., date_created), I had to leave the PHP SESSION code as form_data, and then that data properly carried over to the confirmation page as well (it was missing if I had form_data_multipage in place instead).

    Much thanks again. Your product is awesome; I'm finding new ways to utilize it all the time!

    Joel

    Posted 11 years ago #
  8. yuniar

    The "general" form data, I suppose these are date_created and ip_address?
    If so, we can simply add another code to get these values.

    Below is the complete code to do it:

    $entry_values = mf_get_entry_values($dbh,$form_id,$new_record_id); $_SESSION['form_data_multipage'] = $entry_values; $_SESSION['is_valid_user'] = true;
    
    $query  = "select date_created,ip_address from ".MF_TABLE_PREFIX."form_{$form_id} where id=?";
    $params = array($new_record_id);
    $sth = mf_do_query($query,$params,$dbh);
    $row = mf_do_fetch_result($sth);
    
    $_SESSION['form_data_multipage']['date_created'] = $row['date_created'];
    $_SESSION['form_data_multipage']['ip_address'] = $row['ip_address'];

    replace the code on my previous post with this one.
    You can then access the date_created and ip_address using these two variables:

    echo $_SESSION['form_data_multipage']['date_created'];
    echo $_SESSION['form_data_multipage']['ip_address'];

    MachForm Founder

    Posted 11 years ago #

RSS feed for this topic

Reply