Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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
- //
- // change the 60 here to your form ID
- add_filter('gform_pre_submission_filter_60', 'ch_strtohex');
- function ch_strtohex($form) {
- // input 4 is the form field I want to convert to hex
- $x = rgpost('input_4');
- $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_4'] = $s;
- // return the form
- return $form;
- }
- // http://www.gravityhelp.com/forums/topic/input-on-single-line-text-is-cut-off-after
- // 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 60, field 4 only
- // change to match your form values
- if ($form['id'] == 60 && $field['id'] == 4) {
- $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 60 and field 4), 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 60, field 4 only
- // change to match your form values
- if ($form_id == 60 && $field_id == 4) {
- $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 60 and field 4), return the original value
- return $x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement