How can I use a gravity forms function for a specific form? - gravity-forms-plugin

I have the following code which helps me to move the deleted gravity forms entries to trash instead of deleteting them permanently at gravityview panel. I have multiple forms, I just need this code to be applied on a specific form, not for all other forms. How can I do that?
Note: I am not much good with coding, helping to understand will be highly appreciated.
if ( ! defined( 'WPINC' ) ){
die;
}
add_filter( 'gravityview/delete-entry/mode', '_gravityview_delete_entry_mode_return_trash' );
function _gravityview_delete_entry_mode_return_trash( $mode = 'delete' ) {
return 'trash';
}
Just a quick note: the original snippet was posted on official gravityview site here: https://docs.gravitykit.com/article/299-change-the-delete-entry-mode-from-delete-to-trash if this helps.
Thank you.

Related

Woocommerce checkout: Moving an opt-in field right under the e-mail-field

So I used code snippets successfully for moving checkout fields around, for example moving the e-mail-field on first position with this code:
add_filter( 'woocommerce_billing_fields', 'bbloomer_move_checkout_email_field' );
function bbloomer_move_checkout_email_field( $address_fields ) {
$address_fields['billing_email']['priority'] = 1;
return $address_fields;
}
But what I want to do now by using code snippets, is to move an opt-in consent field right under the e-mail-field that I positioned with the code above.
https://i.postimg.cc/CLZdk54r/fdfdfdffdf.png
The classes of this opt-in-flied are: growmatik_consent_wc_checkout and the outer one growmatik-consent.
I tried a couple of things, but nothing went successfully.
The following code seems to do what I want to accomplish with the klaviyo opt in and the flow-checkout plugin (added to this path: wp-content/plugins/fluid-checkout/inc/checkout-steps.php), I guess it could be re-written so that it works from the normal functions.php and with the growmatik-consent class instead of the "kl_newsletter_checkbox" class:
/**
* Return list of checkout fields for contact step.
*/
public function get_contact_step_display_field_ids() {
return apply_filters( 'fc_checkout_contact_step_field_ids', array(
'billing_email','kl_newsletter_checkbox'
) );
}
I don’t know if you would need anything else and if you even can help me, but it would be really amazing!
Here is a staging of the page where you could actually go to the checkout:
https://wordpress-858200-3004984.cloudwaysapps.com/index.php/product/patterned-wrap-dress/
Thank you so much for your time and maybe even answer!
With kind regards
Chris

Get submission ID ninja forms

I need to grab the submission ID of a form that is being processed. Does anyone know how to do this during ninja_forms_post_process?
I've tries using $ninja_forms_processing->get_field_value and seeing if it was stored there but it doesn't seem to be which makes sense since it's not form field.
Cheers!
I emailed their great support and here's the answer:
$ninja_forms_processing->get_form_setting( 'sub_id' )
The sub_id doesn't populate until ninja_forms_post_process at priority 10, so you need to use something like the below to get the ID of the current submission:
add_action( 'ninja_forms_post_process', function () {
global $ninja_forms_processing;
var_dump( $ninja_forms_processing->get_form_setting( 'sub_id' ) );
}, 11 );
You can simply grab the form id which is submitted either you have one or more ninja forms Go to functions.php in wordpress theme(active theme) ,you must include
global $ninja_forms_processing;
in order to access the things in ninja forms here is all code for it
add_action( 'ninja_forms_post_process', function () {
global $ninja_forms_processing;
$form_id = $ninja_forms_processing->get_form_ID();
echo $form_id;(you will get the form id which is submitted)
}

Joomla: Is there a module render plugin event?

Due to some caching issues, I need to explicitly bypass the cache, for a specific module, if certain URL parameters are present. The workaround I've arrived at is to hack the render() function in libraries/joomla/document/html/renderer/module.php, along the lines of:
function render( $module, $params = array(), $content = null )
{
// Existing code:
$mod_params = new JParameter( $module->params );
// My hack:
if ($module->module == 'mod_foo')
{
if (certain URL parameters are present)
{
$mod_params->set('cache', 0);
}
}
...
}
Of course, hacking the core joomla code is a terrible idea, one which I'd like to avoid if at all possible. So, is there an appropriate hook I can plugin to in order to achieve the same? I don't think I can do anything at the module level, since it won't even be inspected if the renderer has already decided to fetch it from cache.
To answer the first question no there isn't a module render event, here's the plugin doc's and the list of events in Joomla!
Turn off caching for your module.
See this article on The Art Of Joomla, additional articles you could look at:
Using Cache to Speed Up your code
JCache API

Multi-Page Form in Zend is Validating All Forms too early

I have been working through the Multi Page forms tutorial in the Zend Form Advanced Usage section of the documentation, http://framework.zend.com/manual/en/zend.form.advanced.html.
My first page loads fine, however when I submit it, the second page loads and it includes validation error messages. (Obviously I don't want to see validation errors for this page until the user has filled in the fields...)
I have tracked it down to the final line in the formIsValid() function. It seems that here validation is run for all elements in the three forms (not just the current one), so it's really no surprise that errors are showing on the second page.
I have tried the suggestion in the comments at the end of the tutorial, i.e. $data[$key] = $info[$key].
Have you had a crack at this tutorial? How did you solve the problem?
Any assistance is much appreciated!
I encountered the same problem this is how I solve it.
By replacing
public function formIsValid()
{
$data = array();
foreach ($this->getSessionNamespace() as $key => $info) {
$data[$key] = $info;
}
return $this->getForm()->isValid($data);
}
With
public function formIsValid()
{
$data = array();
foreach ($this->getSessionNamespace() as $key => $info) {
$data[$key] = $info[$key];
}
return (count($this->getStoredForms()) < count($this->getPotentialForms()))? false : $this->getForm()->isValid($data);
}
The documentations reads:
Currently, Multi-Page forms are not
officially supported in Zend_Form;
however, most support for implementing
them is available and can be utilized
with a little extra tooling.
The key to creating a multi-page form
is to utilize sub forms, but to
display only one such sub form per
page. This allows you to submit a
single sub form at a time and
validate it, but not process the form
until all sub forms are complete.
Are you sure you have been validating a single sub-form instead of just whole form?

What's the best method to generate Multi-Page PDFs with Perl and PDF::API2?

I have been using PDF::API2 module to program a PDF. I work at a warehousing company and we are trying switch from text packing slips to PDF packing slips. Packing Slips have a list of items needed on a single order. It works great but I have run into a problem. Currently my program generates a single page PDF and it was all working fine. But now I realize that the PDF will need to be multiple pages if there are more than 30 items in an order. I was trying to think of an easy(ish) way to do that, but couldn’t come up with one. The only thing I could think of involves creating another page and having logic that redefines the coordinates of the line items if there are multiple pages. So I was trying to see if there was a different method or something I was missing that could help but I wasn’t really finding anything on CPAN.
Basically, i need to create a single page PDF unless there are > 30 items. Then it will need to be multiple.
I hope that made sense and any help at all would be greatly appreciated as I am relatively new to programming.
Since you already have the code working for one-page PDFs, changing it to work for multi-page PDFs shouldn't be too hard.
Try something like this:
use PDF::API2;
sub create_packing_list_pdf {
my #items = #_;
my $pdf = PDF::API2->new();
my $page = _add_pdf_page($pdf);
my $max_items_per_page = 30;
my $item_pos = 0;
while (my $item = shift(#items)) {
$item_pos++;
# Create a new page, if needed
if ($item_pos > $max_items_per_page) {
$page = _add_pdf_page($pdf);
$item_pos = 1;
}
# Add the item at the appropriate height for that position
# (you'll need to declare $base_height and $line_height)
my $y = $base_height - ($item_pos - 1) * $line_height;
# Your code to display the line here, using $y as needed
# to get the right coordinates
}
return $pdf;
}
sub _add_pdf_page {
my $pdf = shift();
my $page = $pdf->page();
# Your code to display the page template here.
#
# Note: You can use a different template for additional pages by
# looking at e.g. $pdf->pages(), which returns the page count.
#
# If you need to include a "Page 1 of 2", you can pass the total
# number of pages in as an argument:
# int(scalar #items / $max_items_per_page) + 1
return $page;
}
The main thing is to split up the page template from the line items so you can easily start a new page without having to duplicate code.
PDF::API2 is low-level. It doesn't have most of what you would consider necessary for a document, things like margins, blocks, and paragraphs. Because of this, I afraid you're going to have to do things the hard way. You may want to look at PDF::API2::Simple. It might meet your criteria and it's simple to use.
I use PDF::FromHTML for some similar work. Seems to be a reasonable choice, I guess I am not too big on positioning by hand.
The simplest method is to use PDF-API2-Simple
my #content;
my $pdf = PDF::API2::Simple->new(file => "$name");
$pdf->add_font('Courier');
$pdf->add_page();
foreach $line (#content)
{
$pdf->text($line, autoflow => 'on');
}
$pdf->save();