Chronoforms field to insert dynamic data - php

I am needing to have a custom element that will look at a drop-down called month and conditionally insert the numeric month into the database. For example if the user selects October it would put the number 10 in the numeric_month field in the DB. The month drop-down is set to another field in the same database and unfortunately there is no way to combine them for our purposes. Any help would be appreciated. I am new to php coding.

Create a hidden field in your form for numeric_month
add a "Custom Code" action to the "On Submit" event before your "DB Save Action"
In the Custom Code action insert PHP code to set the numeric_month field to the appropriate value depending on the selected drop down value.
In ChronoForms v4 or v5, this will be something similar to this:
<?php
$form->data['numeric_month'] = date("n",strtotime($form->data['month']));
?>
This would set numeric_month to '7' for a month value of 'July'.
Use date("m",strtotime($form->data['month']) to set numeric_month to '07' instead.
For more information about the PHP code to convert a month name to a numberic string, see the answers to these questions:
convert month from name to number
PHP convert short month-name to month-number

Related

how to create Dynamic Input value with two different datatype time and text and insert into one single column

I have Dynamic Input box with Time Input and Text Input I want to show as a list items and also wanted to insert values in one column of table in SQL
example :
09.30 PM Saturday night journey begins.
01.30 AM We Reach the Base village
02:00 AM Some Yumm, Breakfast!
How to add multiple input for list item with two different datatype time and text ??
you are getting into complex code, make two different Varible/text Input/columns
if you still want use them add something in between and use Sting function like : strlen() / stripos() / stristr() ---- and while using it in code make two different variables
example value [startTime09.30 PM - ReachTime 10.00AM]
Get Lenth of Text strlen() [44Charecters] >> find position of "-" stripos("-")[23rd postion] >> Chop strings left part and store it in variable do same with remaining

SugarCRM Field Calculation example of ifElse

I am new to SugarCRM. I have a requirement to calculate a field value through studio. But, in one of the fields which comes in denominator can be 0. So, i want to modify the formula through ifElse, how to do that.
Example - If (field1>0){calcField/field1} else(calcField=0).
you can use calculated field , if else like this:
ifElse(equal($status,"Held"),1,0)
For more information check this link :
Calculated field in sugarcrm

Get highest custom field value from last x months

in Wordpress, I've got a category called "Reviews" where I assign a vote (in a custom field called 'rate') to every single post I create in this category.
Now I'm trying to get the review with the highest rate in the last X months.
The rate ranges from 0 to 10, with one decimal number (ex. 5.3, 7.4, 9.1).
How can I do this? Use WP_Query or direct DB query? Thanks in advance.
You can use something like this to get the highest rating:
SELECT max(cast(meta_value as unsigned)) FROM wp_postmeta WHERE meta_key='your_meta_name'
But post meta data does not hold the date/time value for you. You need to think a way to insert date value as well.

How to implement Different format for 1 field in jqgrid

I have table configuration for my site like this in JQGRID
configid config rule
1. Aplication_name 'MyApps'
2. Max number 1,000,00
3. Application End 12/31/2012
One cell type's number but other's date. And If User want to edit date type , it shown datepicker.
How Do I Do that?
Thanks,
There is an example of how to use the jQuery UI datepicker with jqGrid on the demo page under Integrations | UI Datepicker.
Is there a problem with that demo or something more that you need the grid to achieve?

PHP MySQL insert values from multiple checkboxes into one column in table

I have a form that a user would fill out while creating a ticket for a bug they have found on our website. In the form there is currently an input field where the user would enter in the designs that the bug is affecting (ex., "Design1, Design2, Design3, Design4" ...etc). When the form is submitted the value is stored in a table column named affectedDesigns.
What i am wanting to do is create several checkboxes (one check box for each design we have) that a user would select instead of using the input field. They would be able to select all that apply. If possible i would still like to store all of the values into the affectedDesigns column in one record. I'm thinking that i can gather the selected checkboxes values and create an array or some comma delimited value that contains all of the selected items and submit that to the databasein the one record in the affectedDesigns column. How can i achieve this?
Also, how would i then pull that data and re-populate the checkboxes if they would like to go back later and edit the ticket? Thanks for any help!
I would avoid to store all values within a single field. You'll have a lot of problems once you'll have to do some query because you violate normalization rules.
create an array from your $_POST values keyed on the name of each checkbox, then just serialize that array before insert.... then you can unserialize it when you load it up again
You'll end up using explode() and implode() to convert between string and array.
You need the same answer I'm looking for.
Sprites in Basic language used that system for you to select the bits you wanted ON or OFF for each column (3 cols each sprite: 24 bites), and the sum of all the 8 values gives exactly the unique value that only that combination of elements on/off can give.
The KEY is that each elements adds a value that always is greater than ALL the other previous values added up together.
I.g. Checkboxes values are 1, 2, 4, 8, 16, 32, 64, 128.
E.g. If 3rd and 5th elements are selected (values 4 + 16) the result, 20, will only be obtained by those elements, since the next value 32 is greater than the sum itself and even if you sum up all the values up to the 5th element (value 16) the result will never reach 32 (it will always be 1 less than the next possible value, in this case adds up 31)
Basic language used to do it automatically, and it was easy since the max value was fixed. Each sum was only 8 values long. You need a maximum value to be input to your function to limit the attempts the script would make to "try".
So, THIS is what you need, I just don't know the name.
As soon as I find the name of this technique / math operation I'll post a working function here.
You could also get a binary number with the options, e.g. 01001001011 and then just use the character position to figure out whether that checkbox is on or off.
PS. What kind of answer is "you'll end up using explode or implode"?? That's the answer of the lazy fortune reader. "you'll eat and bleep until you die" :S
Lazy solution: assuming nothing else depends on the IDs of entries in affectedDesigns, just delete all entries for that ticket, then re-enter the submitted $_POST values.
The answer was right in the binary option.
It happens to be that a decimal number converted to binary, gives you EXACTLY the combination of options you need. Ones for the "selected" option and Ceroes for the options not selected (read right to left)
So the trick to save them is easy.
Assign each checkbox a value of 2^index, where index is your checkbox id/order
… and you'll get
2^index0 = 1
2^index1 = 2
2^index2 = 4
2^index3 = 8
…and so on.
Then, you sum up your checkbox values, let's say
$options_dec = sum($_POST['options']); //outputs 5 if options 0 and 2 are selected
That decimal sum, converted to binary shows you exactly which checkboxes were selected:
$options_bin = base_convert ( $options_dec, 10, 2 ); //outputs 0101 (reads right to left)
Now you can convert it to an array, reverse it, and call each matching its index with your checkboxes.
$options_arr = array_reverse( str_split( $options_bin, 1 ) ); //returns array containing "0,1,0,1"
Now populate your checkboxes with a loop. Assuming the checkboxes come in the same order than stored values, and each have a 2^$i.
for($i = 0; $i < sizeof($options_arr); ++$i) {
$checkbox_value = pow ( 2 , $i );
$checked_val = ( $options_arr[$i] ? 'checked' : '');
echo "<input type='checkbox' value='$checkbox_value' $checked_val />\n";
}
Not tested, since I made my version in JavaScript.
Another solution is to grab the option right from the binary string
$checked_val = (boolean) substr( $options_bin , -($i+1), 1 );// +1 because neg substr counts from 1, not 0
If being human readable in the database is not important you could use the PHP serialize function to combine all the rows into one storable string object.
If you want the data in the database to be readable, you could use implode/explode to convert your array to a single string and store as is in a char datatype.
Or if you want the data to be more managable and be able to do queries on it, I would store the checkboxes using the mysql SET datatype rather than a string.

Categories