Gravity Form dynamic population and logic conditional in php - gravity-forms-plugin

sorry for the noob question and the wrong code.
I need that a gravity form field is populated with a different value depending on the amount entered by the user in a number field. Is possible?
I try this code but only with the first value does it work, how can I write it correctly?
add_filter( 'gform_field_value_custom_price', 'my_price' );
function my_price() {
$master = rgpost( `input_22`);
if ( $master < 51 ) {
return 0.80;
} elseif ( $master > 50 && < 201 {
return 0.60;
}
}
Thank you

Since you're populating static values, you could feasibly just create two different fields, each with their unique amount (0.80 or 0.60) and then use conditional logic on each field to show/hide the correct field dependent on the value entered in the Number field.
If the field you're attempting to populate is a Product field, you might consider Gravity Forms Conditional Pricing which would allow to change the price dynamically on a single field rather than requiring two different fields.

Related

Multiple Intervals on Page, How to clear interval only on specific element

I've been having trouble figuring out how to have multiple intervals used on a page. Normally, this wouldn't be a problem but I'm working to create a dynamic countdown script which uses data submitted by the user and have to abide by a few rules:
I need the interval only to clear specifically for given element.
I only need the interval to clear if there currently is an interval set in that specific element.
My idea was to count each interval and assign the number instance to each one. So something like this :
function(element, data, api) {
let intervalIds = [];
for (var i=0; i < intervalIds.length; i++){
}
intervalIds.push(setInterval(function(){
console.log(intervalIds[i]);
clearInterval(intervalIds[i]-1);
//timecalculations after
}, 1000 ));
}
This worked at first, however when I refresh the page with multiple intervals, but after I refresh the page there is only one interval.
If the element ID is the same and a interval has been set for this element then clear the previous interval
If the element ID is different just simply start a new interval
P.S with the software I'm using I can access the element id using data.elementId. ex: if (data.elementId == data.elementId) { do stuff }
I found out the answer to this riddle.
You would need to create a dynamic variable. To do this you would either need to use eval() or assign the variable to the window scope. Then assign the interval to that variable.
Luckily, the software I work with assigns a unique Id to each element added to the page. So I can use this unique Id to assign it to the variable to create the dynamic va
For example:
//unique id
var dynamicIntervalID = $(element).attr('id');
//clear interval if one exists
if (window["intervalIds"+dynamicIntervalID])clearInterval(window["intervalIds"+dynamicIntervalID])
//assign unique element id to interval
window["intervalIds"+dynamicIntervalID] = setInterval(function(){
...code here..
}, 1000 );
Hope this helps.

The caculated number field return 0 after submit form on Gravity form

I cut a 11 characters number field to 4 character by JavaScript in Gravity form. In final I use the output number, in another number field. On form page everything is OK and the number field cut correctly but on back-end side I receive 0.
This is what I use to cut number field:
<script>
gform.addFilter( 'gform_calculation_format_result', function(formattedResult, result, formulaField, formId, calcObj,trimmedresult, output){
if ( formulaField.field_id == '73' ){
formattedResult = gformFormatNumber(result, !gformIsNumber(formulaField.rounding) ? -1 : formulaField.rounding, ',', '');
output = formattedResult.substr(6, 4);
}
return output;
});
</script>
How can I handle it buddies?
For security reasons, Gravity Forms reprocesses the submitted value for calculation fields to ensure that the calculation is untampered. You'll need to do the same logic on the server side. Try the PHP version of this filter: gform_calculation_result
https://docs.gravityforms.com/gform_calculation_result/#php-version

How can I create a search with filters in Angular/Express/MongoDB?

I am trying to mimic the functionality of the right sidebar of this example for my Angular site.
I don't know what this is called, or even how to go about it on the front end or back end!
My assumption:
Create a form with values coming straight from the DB and only show the desired parameter (i.e. db.collection.find(query, {parameter: 1}) which will be called to update each time a user modifies the form. Additionally, the results would also be updated on selection (I have over 100MB of documents, returning ALL of them would be troublesome, how can I limit the number of documents returned to let's say 20 or 50 (user input?) and paginate it (1000 documents returned / 50 per page = 20 'pages')
Each input that is selected, a { 'field' : value } would be returned -- but I am not sure how to control an empty value (i.e. what if a user doesn't pick a fuel type or transmission range?)
How do I go about designing such a feature correctly?
1) In your query, use limit statement:
var options = { "limit": 20 }
collection.find({}, options).toArray(...);
2) you can validate user empty input (for eg. with express-validator):
req.checkBody('postparam', 'Invalid postparam').notEmpty()
req.getValidationResult().then(function(result) {
if (!result.isEmpty()) {
res.status(400).send('There have been validation errors: ' + util.inspect(result.array()));
return;
}
and based on result choose default value/pass error/render ask page for user

How can I access an attribute of a selected parameter in Tableau?

I have a list of Companies with a ROIC measure. Each Company belongs to a Segment.
I created a parameter to select a Company: [SelectedCompany], and I want to create a SET which includes all the companies except the [SelectedCompany], which are in the same [Segment] as [SelectedCompany].
My set is currently defined by this formula:
[Company] != [SelectedCompany]
I should add something like:
[Company] != [SelectedCompany]
AND
[Segment] = [SelectedCompany].[Segment]
But I don't know how to access the [Segment] attribute of the [SelectedCompany].
Just for clarification, I'm making this because I want to compare the [SelectedCompany] ROIC against the average ROIC of the other Companies in the same Segment.
I would appreciate any help on this.
Thanks a lot!
Here's a bit of a hacky way to get what you're looking for. Keep your original definition for the set:
[Company] != [SelectedCompany]
Create a calculated field:
{ FIXED [Segment] : MAX( IIF([Company] = [Parameters].[SelectedCompany], 1, 0) ) }
Then drag that field into the Filters card and filter to allow only 1's. This will filter out all Segments except for the selected company's Segment.

Using cell value as reference to sheet in formulas

I have a spreadsheet with three sheets. Two are called 2012 and 2011 and have a bunch of similar data. The last sheet does comparisons between the data.
To be able to choose year, I'm using a cell (D1) where I can I can write either 2011 or 2012. The formulas then use the INDIRECT function to include this cell as part of the reference.
INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!F:F")
This is not a pretty solution and makes the formula quite long and complex.
=IFERROR(SUM(FILTER( INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!M:M") ; (INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B")=$A4)+(INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B")=$A5)+(INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B")=$A6)+(INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B")=$A7)+(INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B")=$A8); MONTH(INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!D:D"))=$B$1 ; INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!F:F")=D$3));0)
Is there a better way of doing this?
I've tried to create a separate spreadsheet for the calculations sheet and importing (IMPORTRANGE) the data from the two sheets together on one sheet with VMERGE (custom function from the script gallery) but there is quite a lot of of data in these two sheets and the import takes a long time. Any changes (like changing year) also take a long time to recalculate.
Database functions tend to be cleaner when doing this kind of thing.
https://support.google.com/docs/bin/static.py?hl=en&topic=25273&page=table.cs&tab=1368827
Database functions take a while to learn, but they are powerful.
Or
You could put INDIRECT(CHAR(39)&$D$1&CHAR(39)&"!B:B") in a cell on its own.
I think that you have two years of information where the schema is identical (column C has the same type of information on both sheets). Also, I'm assuming that column B tracks the year.
If so, consider holding all of your information on one sheet and and use the spreadsheet function "QUERY" to create views.
For instance, this formula returns all the cells between A1:E from a sheet named "DataSheet" where the values in column B = 2010.
=QUERY(DataSheet!A1:E; "SELECT * WHERE B = 2010";1)
Sometimes there is a really good reason to have the data stored on two sheets. If so, use one of the vMerge functions in the script gallery to assemble a working sheet. Then create views and reports from the working sheet.
function VMerge() {
var maxw=l=0;
var minw=Number.MAX_VALUE;
var al=arguments.length ;
for( i=0 ; i<al ; i++){
if( arguments[i].constructor == Array )l =arguments[i][0].length ;
else if (arguments[i].length!=0) l = 1 ; // literal values count as array with a width of one cell, empty cells are ignored!
maxw=l>maxw?l:maxw;
minw=l<minw?l:minw;
}
if( maxw==minw) { /* when largest width equals smallest width all are equal */
var s = new Array();
for( i=0 ; i<al ; i++){
if( arguments[i].constructor == Array ) s = s.concat( arguments[i].slice() )
else if (arguments[i].length!=0) s = s.concat( [[arguments[i]]] )
}
if ( s.length == 0 ) return null ; else return s //s
}
else return "#N/A: All data ranges must be of equal width!"
}
Hope this helps.