How to change the entry id of gravity forms after submit - gravity-forms-plugin

How can I change the entry id of the form in this case I want to change the form entry number to the current user id that is logged in on the site. I've tried the function below but the entry id saved on the database is not changing
add_filter( 'gform_entry_id_pre_save_lead', 'my_update_entry_on_form_submission', 10, 2 );
function my_update_entry_on_form_submission( $entry_id, $form ) {
$update_entry_id = rgpost( 'input_4',true );
return $update_entry_id ? $update_entry_id : $entry_id;
}

Related

Gravity Forms - Dynamically populate a drop down based on entries from another gravity form

So I am looking at dynamically populating a drop down field in a form with entries from another gravity form. Based on that choice, I will populate a second drop down dynamically based on entries from a gravity form.
More or less I am creating the ability to submit a work order. In that work order I want users to select a piece of equipment then based on that piece of equipment they can select a part.
I have looked at gform_get_entries_args_entry_list as a way of snagging entries, but I am not overly sure how to set it so it pulls from a particular form.
add_filter( 'gform_get_entries_args_entry_list', 'machine' );
function populate_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
$items = gform_get_entries_args_entry_list( 'NOT SURE WHAT TO PUT HERE' );
$choices = array();
foreach ( $items as $GRAVITY FORM ENTRY VARIABLE) {
$choices[] = array( 'text' => $GFEV->THE MACHINE NAME, 'value' => $GFEV ->The Name Field of the machine );
}
$field->placeholder = 'Select a Post';
$field->choices = $choices;
}
return $form;
}
The Gravity Forms Dynamic Population Pro plugin uses the GFAPI:get_entries function, which you can just directly pass the form ID.
Here's the definition:
public static function get_entries( $form_ids, $search_criteria = array(), $sorting = null, $paging = null, &$total_count = null )

gravity forms Form Entry - display label, not value for checkboxes, select

I've got checkboxes and selects where label is different to its value.
In the DB the value is saved ok, however, when viewing Form Entries (and pre-submit form data) for all the checkboxes and selects the values are displayed not labels. So I end up with not so informative IDs rather than names.
Is there a way to display labels instead of values in the Form Entries screen?
I came across your question while looking to do the same thing. I have a field called Account Type that stores the account type ID as the value. In the entries list I want to show the account type name, not the ID.
Here's the solution:
In your theme's functions.php file add the following filter:
add_filter( 'gform_entries_column_filter', 'modify_entry_view', 10, 5 );
You'll find the documentation for it here: https://docs.gravityforms.com/gform_entries_column_filter/
Then add the function code:
function modify_entry_view( $value, $form_id, $field_id, $entry, $query_string ){
//- Check the field ID to make sure you only change that one
if( $field_id == 14 ){
return 'modified value';
};
return $value;
}
In my case I'm using a custom field that I created called account_type that prepopulates a select menu with choices corresponding to each of the account types in our system. I used the following call to check the field type instead of checking based on field id since the id will change from form to form:
if( RGFormsModel::get_field( $form_id, $field_id )->type == 'account_type' ){
You could do the same thing but use the label property instead of type, like:
if( RGFormsModel::get_field( $form_id, $field_id )->label == 'Field Label' ){
In my case the value saved is a term id from a custom taxonomy I set up called account_type, so I simply use:
return get_term_by( 'id', $value, 'account_type' )->name;
to replace the account id with the account name.
FYI: The process is the same for the entry detail, use the filter documented here: https://docs.gravityforms.com/gform_entry_field_value/

Wordpress GravityForm autosubmit with a parameter

I have a requirement to auto-submit a GravityForm with a form parameter. So, as far as I know GravityForms has the ability for you to send a parameter through the URL and it'll automatically fill out a field for you. What I want to do is the ability to send another field called autosubmit=true in which if that is on there, it will automatically submit the form.
Here is a generic solution for any form: Automatically submit a form
And here is a Gravity Forms specific solution: https://www.gravityhelp.com/forums/topic/autosubmit-with-gravity-forms
The basic premise of both is that you use Javascript to trigger the form submission when the page loads. You would need to make yours conditional so that it checks the value of your pre-populated autosubmit field.
<script>
jQuery( document ).ready( function() {
// Update "1" to your form ID and "2" to your prepop field ID
if( jQuery( '#input_1_2' ) == 1 ) {
// Update "1" to your form ID
jQuery( 'form#gform_1' ).trigger( 'submit' );
}
} );
</script>

Save the user_id of a logged in user when submitting a form in ZF2

I want to save the users user_id along the data he submits via a form. This is in my controller:
The controller:
$request = $this->getRequest();
if ($request->isPost()) {
$testing = new Testing();
$form->setInputFilter($testing->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$this->zfcUserAuthentication()->hasIdentity(); // user logged in?
$user = $this->zfcUserAuthentication()->getIdentity(); //get identity
$user_id = $user->getID(); //gets the user-id, output: number, eg. 18
$testing->exchangeArray($form->getData());
$this->getTestingTable()->saveTesting($testing);
// Redirect to iaps test
return $this->redirect()->toUrl('/testing/iaps4');
}
}
return array('form' => $form);
}
If I print_r($user_id) the output will be plain and simple 18.
I tried several things that did not work, here the most promising ones:
a seperate exchangeArray for the user_id only. Unfortunately, it
only generates an empty entry in my database along the data form.
combine the $testing->exchangeArray($form->getData()); with the
user_id data, obviously no success here either.
The thing is, I kinda know what I need: the plain output 18 from the $user->getID(); won't help me, because I need to asign this number to the user_id column in the database along the data submitted by the user with the id user_id.
I'm using Zend Framework 2.3.3, ZF-Commons/ZfcBase 0.0.1 and ZF-Commons/ZfcUser 1.2.2
You can merge user_id with the data from your form in a single array with array_merge :
$testing->exchangeArray(array_merge(
$form->getData(),
['user_id' => $user->getID()]
));

Magento insert and filter multi-select values in custom admin-grid module

I have created a custom module with Module Creator (v 1.7).
Have one multi-select admin form field.
As the multiselect field on submitting gives array , the same value (i.e Array) is stored in database.
To avoid this on saving the submitted value , I just manipulated the code by storing it in e.g a,b,c form.
Through this the data is saved successfully.
Now in grid , I want to filter it , as we have for Status part [1=>Enabled 2=>Disabled].
please suggest How would I achieve this .
Take a look at magento filter_condition_callback option
$this->addColumn('categories', array(
....
'filter_condition_callback' => array($this, '_applyMyFilter'),
..
)
);
protected function _filterCategoriesCondition($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return;
}
$this->getCollection()->addFieldToFilter('categories', array('finset' => $value));
}
See
Filtering a text-type column with MySQL-computed values in Magento Admin Grid
Magento: How to search or filter by multiselect attribute in admin grid?