Search code examples
gravityforms

Gravity Forms - How to add values from multiple inputs to one textarea


OK, so I have a gravity form that contains some input fields. I am trying to take the values from some of those inputs and have them appear in a hidden field. If I try the method that Gravity Forms provides then it works without an issue

add_action( 'gform_pre_submission', 'pre_submission_handler' );
function pre_submission_handler( $form ) {
    $_POST['input_23'] = rgpost( 'input_11' );
}

The issue here is that I am only grabbing a value from one input (input_11). I need to be able to grab values from multiple fields. Here is what I have tried, with no luck

add_action( 'gform_pre_submission', 'pre_submission_handler' );
function pre_submission_handler( $form ) {
    $_POST['input_23'] = rgpost( 'input_11' ) + rgpost( 'input_10' ) + rgpost( 'input_8' );
} 

and...

add_action( 'gform_after_submission', 'pre_submission_handler' );
function pre_submission_handler( $form ) {

        $value_one = rgpost( 'input_10' );
        $value_two = rgpost( 'input_8' );
        $value_three = rgpost( 'input_11' );

    $_POST['input_23'] = $utm_campaign + $utm_source + $message;    
} 

So any ideas on what I could be missing or haven't tried???


Solution

  • Try using . to concatenate your values (rather than +):

    add_action( 'gform_pre_submission', 'pre_submission_handler' );
    function pre_submission_handler( $form ) {
        $_POST['input_23'] = rgpost( 'input_11' ) . "\n" . rgpost( 'input_10' ) . "\n" . rgpost( 'input_8' );
    }