PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

need help on how to use gform_save_field_value()

  1. ax10
    Member

    Hi,

    Rather late here and my brain is stuck. Basically I'm trying to understand how to use the gform_save_field_value() and gform_get_input_value() filters to
    a) encode/encrypt an entire form or
    b) just a particular field in a form.

    In the docs - what is 10, 4? I thought it was in relation to the field and form ids?

    <?php
    add_filter("gform_save_field_value", "save_field_value", 10, 4);
    function save_field_value($value, $lead, $field, $form){
    return base64_encode($value);

    }

    add_filter("gform_get_input_value", "decode_field", 10, 4);
    function decrypt_field($value, $lead, $field, $input_id){
    return base64_decode($value);
    }
    ?>

    My form is at http://tinyurl.com/bvrcqh5

    My form ID is 2, and the 'Telephone' field is field ID 4.

    Thanks
    ax10

    Posted 12 years ago on Monday July 16, 2012 | Permalink
  2. 10 is the priority that the action runs at (default priority is 10) and 4 is the number of arguments the function will accept. Please see the WordPress documentation here: http://codex.wordpress.org/Function_Reference/add_filter

    Once you have an understanding of the add_filter function, we'll take it from there.

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  3. ax10
    Member

    Hi Chris,
    Ok head is clearer this morning, I understand the '10,4' args in add_filter() now thanks.

    Also I'd blindly copied the code in the docs for gform_get_input_value example and there is an error in that the add_filter() is referencing a function called 'decode_field' but in sample code its called 'decrypt_field'... which gave me odd results. http://www.gravityhelp.com/documentation/page/Gform_get_input_value

    Ok with that out of the way; I presume that if I just (as per sample code)

    return base64_encode($value)

    and

    return base64_decode($value)

    in their respective functions every GF form and every field will get encoded/decoded right?

    Q1. Is this safe to use as is for advanced fields (name, address) and checkboxs/radio buttons? Do these need to be treated any differently?

    Q2. Any sample code on how to say just target a particular field within a specific form?

    Q3. Ideally I'd like to use some encryption code rather than base64 encoding - any suggestions?

    Many thanks

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  4. ax10
    Member

    Ok - made some progress today (head must be feeling better).

    Thought I'd share an option incase anyone else finds it of any use.

    Problem: I wanted the captured form data to be encoded/encrypted in the database. Using the sample code gets you started but its only really base64encoded. Searching around I came across this article - http://ideone.com/yQIAX which used "mcrypt".

    So basically pop this code in - instead of the base64_encode... (note) you'll need the mcrypt extension for php enabled.

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  5. You can use whatever PHP function you like for encryption, and as you discovered, you can just swap out the function.

    Does that resolve your issue?

    Posted 12 years ago on Wednesday July 18, 2012 | Permalink
  6. ax10
    Member

    Yes sorted thanks

    Posted 12 years ago on Monday August 13, 2012 | Permalink