The caculated number field return 0 after submit form on Gravity form - gravity-forms-plugin

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

Related

Crystal Reports page numbering

I am using CR to create a catalogue from multiple sales quotes. I will print these multiple quotes into a binder as a sales catalogue.
My issue is that the page numbering needs to start at a different value based upon the quote's final place in the catalogue. I have the following formula referencing a UDF on the sales order header
{OQUT.U_CatPageNo} as the starting page number: -
IF PageNumber = 1 Then
{OQUT.U_CatPageNo}
Else
{OQUT.U_CatPageNo}+PageNumber-1
This works fine on both the left and right side of the page footer. My issue comes when trying to suppress the number based upon whether it is a left or right facing page. I am using the following formula: -
IF {OQUT.U_GLKREF} = 'L' Then PageNumber MOD 2 = 1
{OQUT.U_GLKREF} indicates whether it is a 'L' for left or 'R' for right-facing page however, the syntax seems to be ignoring the {OQUT.U_GLKREF} = 'L' segment.
Ok, after some rest time and clearer thing I think I have solved it this way: -
For the left page i'm using: -
IF{OQUT.U_GLKREF} = 'R' Then PageNumber MOD 2 = 1
Else
PageNumber MOD 2 = 0
For the right page i'm using: -
IF {OQUT.U_GLKREF} = 'L' Then PageNumber MOD 2 = 1
It seems to be solid so far.

Gravity Form dynamic population and logic conditional in php

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.

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

jquery add numbers within one input field

I have found ways to add the numbers of multiple input fields together and output the result. However I am trying to find a way to add numbers within one field, if possible. I basically want it to work as if it was an excel cell and add up numbers using a + in between each one.
So as the user enters =125+11+110 it automatically is adding those numbers to and displaying the total next to the box.
You can split the string:
var expression = "125+11+110";
var operands = expression.split("+");
var sum = 0;
for (var i = 0; i < operands.length; i++) {
sum += parseInt(operands[i]); // use parseFloat if you use decimals as well.
}
But the above example will not know hot to do multiple types of operations in single text box. For example, 100+76-45 will give you incorrect answer.
You can also use eval, but know that it can be harmful if you used it in a wrong way.
var expression = "125+11+110";
var sum = eval(expression);
If you use eval:
do not store the strings user submitted in the database without sanitation.
do not send back the strings user submitted to the browser as JavaScript.
to be safe, just do not even send the user's strings to server at all.
This is the dirty method. It splits the input between the plus signs and adds up the values in the array:
var userinput = "125+11+110";
var userinputarray = userinput.split("+");
var totalamount = 0;
$(userinputarray).each(function(key,value){
totalamount += parseFloat(value);
})
It does not handle subtraction. However you can do a regex match instead:
var userinput = "125+11+110";
var userinputarray = userinput.match(/(\+|\-){0,1}[0-9.]{1,}/g);
var totalamount = 0;
$(userinputarray).each(function(key,value){
totalamount += parseFloat(value);
});
Parsefloat will remove the + symbol, while still using the negative sign.
var data = $('#inputfeildID').text();
var arr = data.split('+');
var total = 0;
for(i=0; i < arr.length ; i ++){
total += arr[i];
}
console.log( total );
When user click enter or submit , first get the value or text in the input field & then split it from + , then add the array elements . you will get the total value of the input box ..
if you want to add those number automatically when user is typing , you have to use jQuery keyup function & when user press + , then add the next number to previous one
You can put a keyup listener on the text box. Then in the code fired by the listener, if "myinput" is the id of your input field:
var exp = document.getElementById('myinput').value;
var result = eval(exp);
"result" will be the value of the expression. You should also really check "exp" to see that it is a valid entry, because the user could put any kind of garbage into the input field, and there could also be security issues.
You should use eval. Like so...
var input = "125+11+110";
var answer = eval(input);
http://www.w3schools.com/jsref/jsref_eval.asp

How to identify the current row in an Apex Tabular Form?

Friends,
I have written the following JavaScript to ascertain which row of an tabular form the user is currently on. i.e. they have clicked a select list on row 4. I need the row number to then get the correct value of a field on this same row which I can then perform some further processing on.
What this JavaScript does is get the id of the triggering item, e.g. f02_0004 This tells me that the select list in column 2 of row 4 has been selected. So my Javascript gets just the row information i.e. 0004 and then uses that to reference another field in this row and at the moment just output the value to show I have the correct value.
<script language="JavaScript" type="text/javascript">
function cascade(pThis){
var row = getTheCurrentRow(pThis.id);
var nameAndRow = "f03_" + row;
var costCentre = $x(nameAndRow).value;
alert("the cost centre id is " + costCentre);
}
// the triggerItem has the name fxx_yyyy where xx is the column number and
// yyyy is the row. This function just returns yyyyy
function getTheCurrentRow(triggerItem){
var theRow = triggerItem.slice(4);
return theRow;
}
Whilst this works I can't help feeling that I must be re-inventing the wheel and that
either, there are built-in's that I can use or if not there maybe a "better" way?
In case of need I'm using Apex 4.0
Thanks in advance for any you can provide.
Well, what you have described is exactly what I typically do myself!
An alternative in Apex 4.0 would be to use jQuery to navigate the DOM something like this:
var costCentre = $(pThis).parents('tr').find('input[name="f03"]')[0].value;
I have tested this and it works OK in my test form.