i have some fields in my database table,and a field with phone name , i save value to this filed like this 111-222-5555
now i want to read all of my fields , and populate to my form , i like populate phone filed to 3 elements(as text element)
when i try this code
$id = $this->_request->getParam ( 'id' );
$values = $cutomModel->findCustomerById($id);// return array of row
$frm->populate($values);
all fields show in form except phone field ,
how can i populate phone field to 3 elements
thanks
If I understand your question correctly, firstly you need to create 3 separate form fields (something along the lines of phone_1, phone_2 and phone_3) to hold the 3 separate phone segments. Then before populating the fields, separate the database output of 1 field into 3 fields.
$id = $this->_request->getParam ( 'id' );
$values = $cutomModel->findCustomerById($id);// return array of row
// split phone number into 3 values
list($values['phone_1'], $values['phone_2'], $values['phone_3']) = explode('-', $values['phone'], 3);
$frm->populate($values);
Finally, before inserting form input into your database you must combine the input from the 3 fields into 1 field.
$values = $frm->getValues();
// combine phone number into 1 value
$values['phone'] = implode('-', $values['phone_1'], $values['phone_2'], $values['phone_3'])
$cutomModel->insert($values);
From what I (hardly) understood, you are trying to fill 3 elements of a form with the content of one field (phone) in your database table.
To achieve this you can use the setDefault() method of the Zend_Form object. Something like this:
$frm->setDefault('field_name', $values->phone);
Do this after populate() and for every field that you want a customized value to be filled.
Related
In my table there are 5 rows and i want to get data from the table on the basis of inputs .the rows are name,age,height,weight and class.
If user inputs age= 12 and weight=40 then person with 12 age as well as 40 weight should be shown.
if user inputs only name=jack then persons with name jack should be shown.
if user inputs all five entries then all entries should be matching.
user can input one field or all five fields.
I suggest to use the inputs to build an associative array which contains the filters you want to apply.
$filters = array();
if (!empty($this->input->post('name')))
$filters['name'] = $this->input->post('name');
if (!empty($this->input->post('age')))
$filters['age'] = $this->input->post('age');
if (!empty($this->input->post('height')))
$filters['height'] = $this->input->post('height');
if (!empty($this->input->post('weight')))
$filters['weight'] = $this->input->post('weight');
if (!empty($this->input->post('class')))
$filters['class'] = $this->input->post('class');
Then, when you are building your query, you just need to iterate over the array:
foreach ($filters as $key => $value) {
$this->db->where($key, $value);
}
Note the use of empty() instead of isset or any manual comparison. Docs reference.
I can print the hidden posted value properly but when i submit to database value is shown as zero in database table .im posting a integer value and int is the datatype given in database.
$array = array(
"unit_id"=>$this->input->post("unit_id"),
"head_id"=>$this->input->post("unit_head_id"),
);
$this->db->insert('request', $array);
Its not issue of hidden fields
in controller you have to match correct key value for the fields, please cross verify it
$array = array(
"unit_id"=>$this->input->post("unit_id"),
"head_id"=>$this->input->post("unit_head_id"),
);
$this->db->insert('request', $array);
I need to grab data of entry after post submit, i.e:
function update_campaign_amount($entry, $form) {
$donate_to_personal_camp_form = get_option('als_donate_to_personal_camp_form');
$main_campaign_form = get_option('pb_main_campaign');
if ( $form['id'] == $donate_to_personal_camp_form ) {
$campaign_id = $entry['55'];
$user_donation = $entry['4'];
$total_donations = get_post_meta($campaign_id, 'campaign_current_amount', true);
if (is_numeric($user_donation)) {
update_post_meta($campaign_id, 'campaign_current_amount', $total_donations + $user_donation);
}
}
}
add_action( 'gform_after_submission', 'update_campaign_amount', 10, 2 );
As you can see in the code the two variable $campaign_id and $user_donation gets the value of a specific entries, it works but it doesn't good enough, because today the number of the entry is 55, tomorrow it could be something else.. Is there any other options to get entry value? For example, I have only one field on that form with the type "total", and I need it's value, so I want to do something like:
$entry['type'] == 'numer'
But I could find anyway to get entry data without the use of absolute numbers.
Anyone know more flexible way?
$entry will contain an associative array of all the Field IDs and values for the current form submission. So if your Total field has an ID of 20 you can access the total amount for the current submission like this: $entry['20']. The IDs of the fields don't change so $entry['20'] will always return the total. Further details here:
https://www.gravityhelp.com/documentation/article/entry-object/
If you have lots of different forms and the Field IDs are different for each form then you can use this:
$fields = GAPI::get_fields_by_type( $form, $type );
So if you know that that you only have one number field you can get the ID like this:
$number_fields = GAPI::get_fields_by_type( $form, 'number' );
$my_number_field = $number_fields[0];
$field_id = $my_number_field->id;
We need to extract specific fields, no matter if they have data or not.
If I f.ex. want an putput with only the field with external id : 'logo' i am trying this:
$limit = 10;
$app_id = xxxxxxx;
$items = PodioItem::filter($app_id,array('Limit' => $limit,'external_id' => 'logo'));
Within podio not all the fields are filled in, and the result is that we do not get a return value for field 'logo'.
When we don't get a return from field logo - the array output is not structured in a way so we can grab the data we need.
How do we achieve this ?
Added text
Rough Example on print output:
items[0] = Companyname,Logo,Address,Phone,Country
(has data in Logo)
items[1] = Companyname,Address,Phone,Country,ContactPerson
(no data in Logo)
items[2] = Companyname,Address,Phone,Country
PROBLEMS ARISING
items[2][4] is not existing (but i won't know this)
items[0][2] is Address Field (but i won't know this)
items[1][2] is Phone Field (but i won't know this)
Looking for Company Contact Person [x][4] accross items will end in
[0] = Wrong (country)
[1] = Right data (ContactPerson)
[2] = PHP error
Like in SQL, i would take the coloumn_name_1,coloumn_name_2, etc.. and grab data from only these fields.
PodioItem objects have a collection of item fields. As you've noted only fields that have values are included (since including empty fields is redundant). As you've noted you can't reliably access the fields by their array offset.
What you should do it access it by field_id or external_id. These are the unique identifiers. You can use the field method on the PodioItem object for this purpose:
$items = PodioItem::filter(...);
foreach ($items['items'] as $item) {
// Get field with external_id "logo". You can also pass in field_id
$field = $item->field('logo');
if ($field) {
print "Found a logo field!";
}
}
HI GEEKS
I am working in PHP and Mysql.
I have an array from database, in which I get the values if field name of a form i.e., Name, Company Name, etc. There are lots of field in the array.
I want these field to be displayed in my desired sequence, likewise:
Name:
Company Name:
Date of Birth:
Address:
These values are available in array in unordered format likewise:
array(
Company Name,
Address,
Date Of Birth,
Name
)
Now my question is how can manipulate this array to get the desired sequence in display of fields as shown above in PHP?
I think the better way is you should print them as you need instead of doing sorting on array based on custom desire something like:-
echo $array['Name'];
echo $array['Company Name'];
and so on
OR
if the fields are dynamic and edited by admin then you have to add one more field in your mysql database and store the order number of all the fields by which value to be printed on page.
Thanks
You are using associative array. You can output each key,value in any order you like.
If you want each ordering to be configurable, then simply store the key names in a list in order of appearance. Then display values according to this list of keys.
For eg : array name is user_info in which you have
array(
Company Name,
Address,
Date Of Birth,
Name
)
$user_info[0] = $user_info[3];
$user_info[1] = $user_info[0];
$user_info[2] = $user_info[2];
$user_info[3] = $user_info[1];
Unordered arrays do not exist in PHP. If you don't give them an explicit index, the elements will be indexed numerically starting from 0.
Here is an array:
$pizzas = array(
'boston',
'pepperoni',
'cheese'
);
To get the third value, use
$pizzas[2]
Let's say I want to echo the first value, then the third, then the second:
echo $pizzas[0].$pizzas[2].$pizzas[1];
EDIT: to reorder your array in the way you want, here is what you can do (let's take you would like it ordered as in the previous example:
$pizza_nicely_ordered = array (
$pizzas[0],
$pizzas[2],
$pizzas[1]
);