Good catch! I missed that part.
I'm close!
It's converting to hexadecimal, but not converting back.
dj21j<22j>djj<dk is returning this 646A32316A3C32326A3E646A6A3C646B
The code I'm using is… (form id is 7 and input is 5)
<?php
// http://www.gravityhelp.com/forums/topic/input-on-single-line-text-is-cut-off-after
// this handles converting the entered value to hex for storage
//
// strtohex and hextostr functions lifted from here:
// http://www.php.net/manual/en/function.hexdec.php#100578
//
// gform_pre_submission_filter_7 <--- 7 for FORM ID 7
add_filter('gform_pre_submission_filter_7', 'ch_strtohex');
function ch_strtohex($form) {
// input 5 is the form field I want to convert to hex
$x = rgpost('input_5');
$s='';
// convert the submitted string to hex
foreach(str_split($x) as $c)
$s .= sprintf('%02X',ord($c));
// assign the hex value to the POST field
$_POST['input_5'] = $s;
// return the form
return $form;
}
// retrieve hex and convert before displaying in the admin: single entry view
add_filter('gform_entry_field_value', 'ch_hextostr_single', 10, 4);
function ch_hextostr_single($x, $field, $lead, $form) {
// run this code on form 7, field 5 only
// FORM ID 7, INPUT ID 5
if ($form['id'] == 7 && $field['id'] == 5) {
$s='';
foreach(explode("\n",trim(chunk_split($x,2))) as $h) {
$s .= chr(hexdec($h));
}
// prevent rendering anything that looks like HTML as HTML
return htmlspecialchars($s);
}
else {
// not (form 7 and field 5), return the original value
return $x;
}
}
// http://www.gravityhelp.com/forums/topic/input-on-single-line-text-is-cut-off-after
// retrieve hex and convert before displaying in the admin: entry list view
// note the different filter name here "entries"
add_filter('gform_entries_field_value', 'ch_hextostr_list', 10, 3);
function ch_hextostr_list($x, $form_id, $field_id) {
// run this code on form 7, field 5 only
// change to match your form values
if ($form_id == 7 && $field_id == 5) {
$s='';
foreach(explode("\n",trim(chunk_split($x,2))) as $h) {
$s .= chr(hexdec($h));
}
// prevent rendering anything that looks like HTML as HTML
return htmlspecialchars($s);
}
else {
// not (form 7 and field 5), return the original value
return $x;
}
}
Posted 13 years ago on Tuesday November 8, 2011 |
Permalink