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.

Zebra Print Bikini & gform_pre_submission

  1. I need to take a text that the user inputs into a form, populate a hidden field and slightly manipulate the data prior to saving into the database.

    I want "Zebra Print Bikini" to become "zebra-print-bikini" in a different hidden field.

    I'm new to php. It seems if the 2nd field in my form contained "Zebra Print Bikini", I would I need to do something like this:

    $newVariable = str_replace(" ", "-", input_2);
    $newnewVariable = strtolower($newVariable)

    In Gravity Forms I think I need to use gform_pre_submission. If the hidden field I want to place the new variable in is the first field in my form, I think I'd need to do something like this:

    add_action("gform_pre_submission", "pre_submission_handler");
    
    function pre_submission_handler($form){
    $newVariable = str_replace(" ", "-", input_2);
    $newnewVariable = strtolower($newVariable)
    $_POST["input_1"] = $newnewVariable;
    }

    And, this goes in my bp_custom.php since I'm using BuddyPress?

    Of course, I tried this and it didn't work so I'm asking for assistance. Appreciate it!

    Posted 13 years ago on Monday July 11, 2011 | Permalink
  2. It's not all that pretty, but this is now working!

    add_action("gform_pre_submission_1", "pre_submission_handler");
    
    function pre_submission_handler($form){
    
    global $_POST;
    
    $VariableForceLowerCase = strtolower($_POST["input_2"]);
    $VariableSpaceToDashes = str_replace(" ", "-",
    $VariableForceLowerCase);
    
    $_POST["input_21"] = $VariableSpaceToDashes;
    }

    I struggled to figure out what the input_# was for the field I was working on. Any tip on easily knowing what the field number is?

    Posted 13 years ago on Monday July 11, 2011 | Permalink
  3. You'd get the field input # by inspecting the form markup and seeing what the ID is for that input.

    Posted 13 years ago on Monday July 11, 2011 | Permalink