Gravity forms – bbird.me http://bbird.me WordPress quick tips Wed, 08 Aug 2018 16:39:07 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 How to pass data in Gravity Forms using filter hooks http://bbird.me/how-to-pass-data-in-gravity-forms-using-filter-hooks/ http://bbird.me/how-to-pass-data-in-gravity-forms-using-filter-hooks/#respond Mon, 29 Feb 2016 19:50:32 +0000 http://bbird.me/?p=375 Inside Gravity Forms documentation , you can find out that you can pass data into Gravity Forms by using any

Post How to pass data in Gravity Forms using filter hooks je prvi puta viđen na bbird.me.

]]>
Inside Gravity Forms documentation , you can find out that you can pass data into Gravity Forms by using any of the following 3 methods: hooks, query strings and shortcodes. Let me show you how to pass data using filter hooks. Basically, what you’re looking for is  gform_field_value_$parameter_name() filter. Note the $parameter_name.

The first thing we need is a filter, inside which we put our function that returns some data. There is an example on Gravity Forms website, a quite simple one.

add_filter('gform_field_value_author_email', 'populate_post_author_email');
function populate_post_author_email($value){ 

    $author_email = get_the_author_meta('email', $post->post_author);

    return $author_email;
}

The most important thing is to note that $parameter_name should match the returned variable. At least that’s what I think :).

Let me show you another example I created for this purpose. Nothing spectacular here, only the the function that returns the current post title:

add_filter('gform_field_value_current_post_title', 'get_current_post_title');
function get_current_post_title($the_title){  

    $current_post_title = get_the_title($post->ID);

    return $current_post_title;
}

Now, the question is how do we pass this info into Gravity forms, so that our field is populated dynamically? What we need is variable name, but without the $ sign, and you put this into parameter name inside the chosen field:

Or we can do the following (same thing, different variable):

In any case, you can see that variable name must match the parameter name. And that’s all there is – you are free to create your own custom functions.

Finally, this is the result you get in the front – these fields are populated by default when you open the page or post or any other type of custom post type where you put the Gravity form:

 

Post How to pass data in Gravity Forms using filter hooks je prvi puta viđen na bbird.me.

]]>
http://bbird.me/how-to-pass-data-in-gravity-forms-using-filter-hooks/feed/ 0
How to create multiple columns in Gravity Forms http://bbird.me/create-multiple-columns-gravity-forms/ http://bbird.me/create-multiple-columns-gravity-forms/#comments Tue, 02 Feb 2016 12:41:21 +0000 http://bbird.me/?p=297 If using Gravity forms, It is likely that you will require columns sooner or later. The reason is simple - gravity forms are normally not used for simple contact forms, given their power and the fact that they are not free, so licenses for GF are being purchased by clients who know exactly what are they looking for.

Post How to create multiple columns in Gravity Forms je prvi puta viđen na bbird.me.

]]>
If using Gravity forms, It is likely that you will require columns sooner or later. The reason is simple – gravity forms are normally not used for simple contact forms, given their power and the fact that they are not free, so licenses for GF are being purchased by clients who know exactly what are they looking for.

Some forms tend to be very big, spanning over multiple pages. Thankfully, this feature is built in into gravity forms by default, but creating columns is not. You may be tempted to try any of CSS ready classes, but I’m not really sure how convenient they are for any advanced layout with multiple fields in each column.

As it is the case with most great WordPress plugins, Gravity Forms also offers a wide variety of hooks and actions enabling you to extend its functionality. If you tried to Google something like “GF multiple columns”, there is chance that you stumbled upon this solution, created by some great folks in Jordan Crown Web Design. Afterwards, this solution was slightly altered and published on Stack Overflow. They suggest that you should put this code into functions.php,  but I prefer wrapping the whole thing into plugin, because having multiple columns in Gravity Forms is not a matter of the theme, but a matter of a plugin and I bet that sooner or later you will change the theme and in that case you would lose the column functionality.

1. Add a plugin

So this is how it goes – first we have a plugin ( you can download it here) – not much code added, only plugin headers.

<?php
/**
 * Plugin Name: Gravity Forms Columns
 * Plugin URI: http://www.gravityforms.com/
 * Description: Gravity Forms Columns
 * Author: Multiple Authors
 * Author URI: http://www.gravityforms.com/
 * Version: 1.0
 */

function gform_column_splits($content, $field, $value, $lead_id, $form_id) {
if(!is_admin()) { // only perform on the front end
    if($field['type'] == 'section') {
        $form = RGFormsModel::get_form_meta($form_id, true);

        // check for the presence of multi-column form classes
        $form_class = explode(' ', $form['cssClass']);
        $form_class_matches = array_intersect($form_class, array('two-column', 'three-column'));

        // check for the presence of section break column classes
        $field_class = explode(' ', $field['cssClass']);
        $field_class_matches = array_intersect($field_class, array('gform_column'));

        // if field is a column break in a multi-column form, perform the list split
        if(!empty($form_class_matches) && !empty($field_class_matches)) { // make sure to target only multi-column forms

            // retrieve the form's field list classes for consistency
            $form = RGFormsModel::add_default_properties($form);
            $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below';

            // close current field's li and ul and begin a new list with the same form field list classes
            return '</li></ul><ul class="gform_fields '.$form['labelPlacement'].' '.$description_class.' '.$field['cssClass'].'"><li class="gfield gsection empty">';

        }
    }
}

return $content;
}

add_filter('gform_field_content', 'gform_column_splits', 100, 5);
?>

2. Form settings

The combination of section breaks and few CSS classes is what activates this thing. First of all, you need to add CSS class name on the whole form. Use either two-column or three-column, depending on what kind of layout you want to achieve.

gravity1

3. Section breaks

Once you did this, you can refer the following image – for every column you need, you’ll want to add custom CSS class on section break. That CSS class needs to be gform_column. Be aware that if you don’t put brakes on a page, nothing will appear on that page, so these are kinda mandatory.

gravity2

4. Custom CSS

Eventually, you’ll need some CSS. This is just an example for two columns, so you will likely want to add margins, padding, etc.

.gform_wrapper.two-column_wrapper ul.gform_fields {
display: none;
}
.gform_wrapper.two-column_wrapper ul.gform_fields.gform_column {
display: block;
float: left;
width: 50%;
}
.gform_wrapper.two-column_wrapper ul.gform_column li.gsection:first-child {
display: none;
}

That’s all folks!

Post How to create multiple columns in Gravity Forms je prvi puta viđen na bbird.me.

]]>
http://bbird.me/create-multiple-columns-gravity-forms/feed/ 1