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

Update Link


  1. startupguy
    Member

    Is there a way to create an edit/update link for the form ? If we have someone fill out a form and they don't have all the information handy, it would be nice to send them a hashed link and have them update it...

    -startupguy

    Posted 16 years ago #
  2. yuniar

    Sorry, what do you mean by edit/update link for the form?

    Update the entry? Or update the form?


    MachForm Founder

    Posted 16 years ago #
  3. AMurray
    Pro Member

    I assume Startupguy means to edit the record; in the Admin screen the admin person has the ability to edit the SQL records; so Startupguy wants the ability for users to go back to an existing record to edit it - much like you can do with this forum, if you have posted an answer and want to add to it, you click "Edit" and it allows you to add to that existing posting.

    Posted 16 years ago #
  4. startupguy
    Member

    AMurray is right on the money. Imagine if a form is created to collect information from a customer base. I would like to create a hashed link to each entry (or be able to generate a hashed link on demand) and send it out to individual customers. They would be then be able to click on that link and edit their form entry without admin access...

    Currently editing individual entries are only editable by admin user.

    I have most of that routine worked out...I just have not figured out a easy exit out of the edit form for non-admin users.

    I put together these hash functions in a file (includes/hash-functions.php)

    function create_hash_links ($input) {

    $str_length = strlen($input);
    $key1 = "1 - Several species of small furry animals gathered together in a cave and grooving with a pict.";
    $key2 = time();
    $alg = "rijndael-128";
    $cmode = 'ecb';

    /* open the cipher */

    $iv_size = mcrypt_get_iv_size($alg, $cmode);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM);
    $ks = mcrypt_get_key_size($alg, $cmode);

    /* create key */
    $key1 = md5($key1);
    $key2 = md5($key2);

    $key = substr($key1, 0, $ks/2) . substr(strtoupper($key2), (round(strlen($key2) / 2)), $ks/2);
    $key = substr($key.$key1.$key2.strtoupper($key1),0,$ks);

    /* Encrypt and encode data */
    $enc = mcrypt_encrypt($alg,$key, $input, $cmode, $iv);
    $enc_val = rawurlencode(base64_encode($enc));

    /* encode key */
    $encoded_key = rawurlencode(base64_encode($key));

    $ret_val = "h=". $enc_val . "&k=" . $encoded_key;
    return $ret_val;

    }

    function retrieve_hashed_links($hashed_input) {

    $hash = base64_decode(rawurldecode($hashed_input['h']));
    $key = base64_decode(rawurldecode($hashed_input['k']));

    $alg = "rijndael-128";
    $cmode = 'ecb';

    /* open the cipher */
    $iv_size = mcrypt_get_iv_size($alg, $cmode);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM);

    /* Decrypt encrypted string */
    $decrypted = trim(mcrypt_decrypt($alg, $key, $hash, $cmode, $iv));

    return $decrypted;
    }

    A version of edit_entry.php would then call these functions ...


    $url = retrieve_hashed_links($_GET);
    parse_str($url, $output);
    $form_id = $output['id'];
    $entry_id = $output['edit'];

    if(empty($form_id) || empty($entry_id)){
    die('Invalid Link.');
    }

    //set session value to override password protected form and captcha
    $_SESSION['user_authenticated'] = $form_id;

    if(!empty($_GET['done'])){
    $markup = display_success($form_id);
    }else{

    //get initial form values
    $form_values = get_entry_values($form_id,$entry_id);

    $markup = display_form($form_id,$form_values,'','',$entry_id);
    }

    Posted 16 years ago #
  5. yuniar

    <<I just have not figured out a easy exit out of the edit form for non-admin users.>>

    Hmm.. what if you go like this:

    1) If non-admin user is accessing edit_entry.php, set a special variable to mark this user and store it in a session.

    $_SESSION['is_non_admin'] = true;

    2) When the form is submitted and successful, check for that session variable, if exists then this is a non admin user, log them out (clear the session) and redirect it to any page you need it.


    MachForm Founder

    Posted 16 years ago #

RSS feed for this topic

Reply