I am trying to make a form which will allow them to update their entered unique entry. Suppose there is form which is used to collect, the User Specializations
And this Specializations field is gravity forms multiselect field which is dynamically set. And as they update their specializations also updated in entries tab.
So, i just want to allow they to have this multiselect field updation.
I came across a solution to add multiselect choice dynamically but that only populate the field with all the choices not the user selected also.
So, is there is way to set the user entered choices dynamically?
Possible Solution:
Like we can get the entries and then set search criterion to current user and will get a unique entry and then after we can set these selected values in the choices.
Issue Exists with the above possible solution:
but still there is issue like it will be creating new entry as form dont know it is update operation. So can anyone help?
//Auto Populate Service Field in Form ID=
add_filter('gform_pre_render_2', 'populate_services');
add_filter('gform_pre_validation_2', 'populate_services');
add_filter('gform_pre_submission_filter_2', 'populate_services');
add_filter('gform_admin_pre_render_2', 'populate_services');
function populate_services($form)
{
foreach ($form['fields'] as &$field) {
if ($field->type != 'multiselect' || strpos($field->cssClass, 'populate_services') === false) {
continue;
}
$services = get_specializations();
$choices = array();
foreach ($services as $service) {
$title = stripslashes($service->name);
$choices[] = array(
'value' => $service->ID,
'text' => esc_html($title)
);
}
// update 'Select Duration' to whatever you'd like the instructive option to be
$field->placeholder = 'Select Services';
$field->choices = $choices;
}
return $form;
}
Related
I am working in gravityforms to pre-populate a form with database values dynamically, which is working. I need to be able to specity which of these options is selected by default when the form is built, but I can't find the option to do so. I have seen the placeholder, but I presume this doesnt actualy select anything on the dropdown. I have been unable to find any docs or references that allow me to set the "selected" options once I have built all the text/value pairs in the array and set the choices.
The function (which I have redacted here) works fine and populates the field, I just need to populate a placeholder and/or default selected value.
add_filter('gform_pre_render_1', 'getFieldValues');
add_filter('gform_pre_validation_1', 'getFieldValues');
add_filter('gform_pre_submission_filter_1', 'getFieldValues');
function getFieldValues($form) {
global $wpdb;
foreach ($form['fields'] as $field) {
if ($field->id == '40') {
// get the list of values from the Database
$list1Q = "SELECT <data> FROM <table> WHERE <params> = <value>";
$list1R = $wpdb->get_results($list1Q);
// Generate a nice array that Gravity Forms can understand
if (!empty($list1R)) {
$list1A[] = array();
foreach ($list1A as $listItem) {
// Add current value to the array for dropdown choices
$list1C[] = array('text' => $listItem->variable, 'value' => $listItem->variable);
}
}
// Set choices to field
$field->choices = $List1C;
***** THIS IS WHERE I WOULD LIKE TO SET THE SELECTED VALUE *****
}
}
return $form;
}
If there is a better way to go about populating this field, I am open to suggestions at it seems that the form loads a bit slow using this method. Otherwise, I would love to know how to set a selected choice value after populating the choices.
the quick answer is, there is an option that i found for "isSelected" that can be included in the array when defining choices. I added a ternary operation to match on what I wanted selected and it set the "selected value for me.
$isSelected = ($listItem->variable == "value I want to select") ? true : false;
$list1C[] = array('text' => $listItem->variable, 'value' => $listItem->variable, 'isSelected' => $isSelected);
Adding the ternary choice and changing the array push allowed me to set a value as selected.
So I'm creating an application for clients to fill in an order to calculate the price. The client has to fill in a form, the form will be posted to a table in MySQL. When the order is complete the client gets an overview of his order with the calculated price. I'm having trouble with storing a variable (from tblPanel_Prices) which is related with a variable in tblPaneltypes. So after filling in the form data from column tblPaneltypes and tblPanel_Prices should be stored together in another table. Both tables (types and prices) are related.
The client has to select a type of panel. These types are stored in the table (tblPaneltypes). Every panel has a certain price-categorie (field price_id) which is needed to calculate the price. The prices of the paneltypes are stored in another table (tblPanel_Prices). There is a relation between the tblPaneltypes and tblPanel_Prices (both integer)
So the client fills in the form and selects a certain type of panel, this gets posted (controller) to the table with the function: this->input->post('paneltype').
After this I want to calculate the surface of the panel and make select the right price-category on the field price-id.
So in the form there is a type of panel choosen by the client. This already goes to my table, but I also want to pass the price_id tag in the form.
Then, I would like to get the price_id tag from the table tblPaneltypes to link this with the price_id tag in tblPanel_Prices. The value of the price_id isn't important for the client, so no need to select or show this value. I just need it to calculate the price of the panel (which depends on the type of panel filled in by the client)
Thanks in advance!
Store function in controller
public function store()
{
$this->load->model("orders/panels/Panels");
$this->form_validation->set_rules('amount', 'aantal', 'numeric|required|max_length[2]');
$this->form_validation->set_rules('dwidth', 'paneelbreedte', 'numeric|callback_check_width');
$this->form_validation->set_rules('dheight', 'paneelhoogte', 'numeric|callback_check_height');
$this->form_validation->set_rules('paneltype', 'paneeltype', 'required');
$this->form_validation->set_rules('ral_code', 'ral kleur', 'callback_check_double');
if ($this->auth()) {
if ($this->form_validation->run() == FALSE) {
$this->read_panel();
} else {
$panel = $this->Panels->create__entry(
$this->input->post('order_id'),
$this->input->post('amount'),
$this->input->post('dwidth'),
$this->input->post('dheight'),
$this->input->post('paneltype'),
$this->input->post('panelcategory'),
$this->input->post('color'),
$this->input->post('othercolor'),
$this->input->post('tubes'),
$this->input->post('colorswatch'),
$this->input->post('structurepaint'),
$this->input->post('uv'),
$this->input->post('window'),
$this->input->post('paintwindow'),
$this->input->post('windowsetup'),
$this->input->post('glastype'),
$this->input->post('door')
);
redirect("rail/read_rail?order=" . $this->input->post('order_id'));
}
} else {
login();
}
create__entry in model: at this moment I'm filling in the panelcategory manually in the model in. In the future it should filled in automaticly.
function create__entry($order_id, $amount, $dwidth,
$dheight, $paneltype, $panelcategory, $color,
$othercolor, $tubes,
$colorswatch, $structurepaint,
$uv, $windowtype, $paintwindow,
$windowsetup, $glastype, $door)
{
$this->order_id = $order_id;
$this->amount = $amount;
$this->dwidth = $dwidth;
$this->dheight = $dheight;
$this->paneltype = $paneltype;
$this->panelcategory = $panelcategory;
$this->color = $color;
$this->othercolor = $othercolor;
$this->tubes = $tubes;
$this->colorswatch = $colorswatch;
$this->structurepaint = $structurepaint;
$this->uv = $uv;
$this->windowtype = $windowtype;
$this->paintwindow = $paintwindow;
$this->windowsetup = $windowsetup;
$this->glastype = $glastype;
$this->door = $door;
$this->db->insert(self::TABLE_NAME, $this);
return $this->read__entry($this->db->insert_id());
}
Is there a way to create/update form poll fields based on a content type? For example, I've got a post type called Candidate and I'd like like to dynamically update a poll list when a new Candidate is added, or when one is removed.
The reason I'm looking for this is because I'm creating a voting mechanism for this client and they have requested that users see an image, the name, and brief Bio of who they are voting for. My idea is to tie in the names so that I can target a hidden Gravity Form poll on page so when the voter clicks, it updates the corresponding named checkbox.
I can of course add each Candidate one by one, and then add each candidate one by one in the form, but was hoping there was a way to do that in code. So far I haven't found much other than filters in the Gravity Forms Documentation.
To reiterate, my question here is not the frontend connection, rather how to dynamically update/add an option in a poll field in a form when content is created for a Candidate post type.
Any help would be appreciated.
I believe the solution you're after is documented here:
http://www.gravityhelp.com/documentation/gravity-forms/extending-gravity-forms/hooks/filters/gform_pre_render/
Probably a combination of solution examples #1 and #2 on that page will fit your needs? So -
Create a category of standard Wordpress pages (category name: "Candidates"), and the pages would contain the candidate information (bio, photo, etc).
In your functions.php file for your current theme, you'd add something like the following to pull out that category's worth of posts:
// modify form output for the public page
add_filter("gform_pre_render", "populate_checkbox");
// modify form in admin
add_filter("gform_admin_pre_render", "populate_checkbox");
function populate_dropdown($form) {
// some kind of logic / code to limit what form you're editing
if ($form["id"] != 1) { return $form; }
//Reading posts for "Business" category;
$posts = get_posts("category=" . get_cat_ID("Candidates"));
foreach ($form['fields'] as &$field) {
// assuming field #1, if this is a voting form that uses checkboxes
$target_field = 1;
if ($field['id'] != $target_field) { break; }
// init the counting var for how many checkboxes we'll be outputting
// there's some kind of error with checkboxes and multiples of 10?
$input_id = 1;
foreach ($posts as $post) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if($input_id % 10 == 0) { $input_id++; }
// here's where you format your field inputs as you need
$choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
$inputs[] = array("label" => $post->post_title, "id" => "{$field_id}.{$input_id}");
// increment the number of checkboxes for ID handling
$input_id++;
}
$field['choices'] = $choices;
$field['inputs'] = $inputs;
}
// return the updated form
return $form;
}
i am using zend forms in my zf2 application which has two text boxes. Once i submit the data, i take that and i filter the data array which i use to display it on the table. Once the data is filtered and displayed on the table, the form data is reset.
Is there a way to retain the values in the form even after submission ?
Thats the code i have, on a button click i get into this page and the action is as shown below. So this Page has a table which will get populated based on the two text boxes that i have. When i click the submit button, the data in the textboxes disappear and the data gets populated in the table.
So what i want to do here is, retain the entered values in the textboxes. Can i do that ? I know HTTP is a stateless protocol. I know i can do it using front end client side technologies, just wanted to know if there is a work around to do this.
public function searchAction()
{
//search form instantiation
$form = new SampleForm();
// get the post request
$request = $this->getRequest();
//instantiation of select for querying
$select = new Select();
// get parameters
$artist = $request->getPost('artist');
$title = $request->getPost('title');
//prepare search criteria array
$search = array('artist' => $artist, 'title' => $title);
//remove empty criteria from the search criteria list
foreach ($search as $key => $value) {
if (empty($value)) {
unset($search[$key]);
}
}
$result = $this->getAlbumTable()->fetchAll($select->where($search));
return array(
'albums' => $result,
'form' => $form,
);
}
I finally figured out what i was doing. I just had to do this.
if ($request->isPost()) {
$album = new Album();
$form->setInputFilter($album->getInputFilter());
$form->setData($request->getPost());
}
I am building a form where users will need to be able to add multiple 'children' and fill in details for them. Each child has multiple inputs so to keep it simple we'll say a user is trying to add 2 children and each child requires a first name and a surname.
I aim in using javascript to add the children to a list so a user can enter a first name and surname then press 'add' and this will create hidden inputs for these details. What I am struggling with is geting these form inputs to be grouped by child so effectively what I end up with will be a $_POST array like the following:
$_POST['child'][0]['firstname'] = 'asdads';
$_POST['child'][0]['surname'] = 'vcbcvbc';
$_POST['child'][1]['firstname'] = 'asdads';
$_POST['child'][1]['surname'] = 'vcbcvbc';
Is it as simple as just setting the 'name' attribute on the inputs to name="child[][firstname]" or can someone offer a suitable solution?
javascript:
var children = [[{name:value},{name:value}],[{name:value},{name:value}],....];
php:
for($i=0; $i<sizeof($_POST['children']); $i++)
{
foreach($_POST['children'][$i] as name => value)
{
// process
}
}