Gravity forms $field_values not working - php

I am running the most curent version of WP and Gravity forms. I'm trying to call the form through a template file and pass through a few things like so:
gravity_form(2, $display_title=false, $display_description=true,
$field_values, $ajax=true);
I'm calling the $field_values like so:
$field_values = array("my" => "FOO", "your" => "BAR",);
They are simple not populating into gravity forms. Any ideas?

Make sure to click on the field and then click on the advanced tab and check mark the prepopulate field checkbox. This will drop down a text box in which you can specify a parameter name.

Ok, lets say that your form ID is 7, let me give you a step-by-step answer:
Create your form
Go to advanced
Check "Allow field to be populated dynamically"
Give it a name, eg.: my_name
gravity_form(7, false, false, false, array('my_name'=>'whatever you want to autofill'), false);
Now if you go to that form you will see that the field which had the name my_name has the value whatever you want to autofill.
Hope this helped, bye bye.

This documentation gives some helpful advice on populating fields:
gravityhelp.com/documentation/page/Allow_field_to_be_populated_dynamically
and here is an example of how I populate fields using a hook:
add_filter("gform_field_value_yourparametername", "populate_yourparametername");
function populate_yourparametername($value){
global $post;
$value = get_post_meta( $post->ID,'metakeyname',true);
return $value;
}
In order for this to work, you must check the box in the advanced tab of the form item in your Gravity Form that allows the field to be populated dynamically. Then you need to fill in the input below with 'youparametername'.

Related

PHP - Get value from saved dropdown

I have a plugin in WordPress in which I can make custom field like dropdown etc. Now I need to get the saved value from the dropdown.
I have this:
$vt_city = get_post_meta($cs_job_id, 'cs_post_loc_city', true);
But that displays it meta instead of the value like this: not_filled
And what I need it to show is: Not filled
How can I achieve such thing?
I can't see nothing about it in the doc, but you can use a regex at least
$clean_meta = preg_replace("/^(\w{1})([a-z]*)_([a-z]*)$/","$1$2 $3",$vt_city);

How to add custom field in the content type of Drupal 7

I want to add a custom field which value will come from external API. As example values may be:
array(
'v1'=>'value1'
'v2'=>'value2'
'v3'=>'value3'
)
So, I want to display them in a dropdown menu as field in the content-type article.
I don't it is right answer, but as per my view it is not better to store all values of third party DB.
To achive your goal I will do like this.
Content type Article which include another two fields:
Number field: Id (api_db_id) : v1, v2, v3....
Text Field: Value (api_db_value) E.g: value 1, value 2 ...
These above field will be hidden.
Before render form E.g: by using hook_form_alter we can connect to third party API and get values and populate in select list
E.g:
function myhook_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'article'){
/*
Third Party API connection code which will generate $dropdown_array.
*/
$options = $dropdown_array;
// Alter form
$form['title'] = array(
'#type' => 'select',
'#default_value' => '1',// set default value.
'#options' => $options,
);
}//endif
}
And Final step will before submit form we will assign selected ID and value to our new field .
You should create a custom module to implement your field.
A good tutorial can be found HERE.
You can check out version 7 of the examples module, specifically the field_example which has very good documentation in the code.
Once you get your head around how it (the hooks) works, there really isn't all that much code to write.
Doing it this way is probably much better than trying to alter other types of fields, and it should automatically integrate with views as expected.

WordPress Contact Form 7 Plugin - How to save input data into jquery cookie?

I wonder if there's a way that I can save the user input data from Contact Form 7 into a cookie, preferably the jquery cookie plugin.
By doing so, I can retrieve these values when I visiting some other pages in order to display/re-process these data.
Contact Form 7 contains quite a few files and I am a bit lost. Any ideas or suggestions how to do it? Thanks.
Managed to get the form data from CF7 plugin and save it to jQuery cookie.Here's what I have done. ( kind of a quick and dirty way )
Open scripts.js under includes/js/ directory, and find following line of code
$(data.into).find('form').resetForm().clearForm()
This resets the form so form values will be all empty.
Add the custom code before the code mentioned above
For example, if i'd like to save the name value after email is successfully sent -- We can do this
if(data.mailSent == 1)
{
var name = $('input[name="your-name"]').val();
$.cookie('mycookie_namevalue', name, { path: '/' });
}
your-name is the default value for name attribute, or change it to whatever the value specified in CF7 plugin settings.

Altering the text after a checkbox using the Drupal Form Api

I got the following issue. A clients wants that the text after checkboxes are links to other pages and thus between ...
I have the following code:
$form['boxes_brands'] = array(
'#type'=>'checkboxes',
'#title'=>'<div id="title-container">Merken</div>',
'#options'=>$brandArr,
'#default_value'=>$_SESSION['filter_brands_cat'],
);
=> $brandArr is an array of brands.
I looked in the Form Api of Drupal but I did not find an option to do this. I could alter the values in $brandArr but of course that changes the value of the value attribuut of the input object too.
Using the prefix and suffix options won't do it either because I don't want the checkboxes in the tags too.
Is there a clean way to do this?
Thanks!
If you created the form with the UI, then you should be able to specify something like this in as the options and links would be rendered as links:
google|This is a link to google
yahoo|Yahoo
bing|Bing!
See example:
Otherwise, you should be able to modify the $brandArr accordingly to create links in the label. Doing this should NOT change the value of the attribute as it should be a $value->$label associative array. You just need to change the $label not the $value.

Zend Framework - Static form elements

I have got a form which a user can use to create a new store and to edit an existing one. When this form is being used to edit a store there are certain fields that I want the user to see but not edit eg. store_id. I have explored the different Zend_Form_Elements hoping to find some kind of static element but with no luck.
So my question is, how do I display information using Zend_Form that a user can't edit?
Thanks.
readonly alone is not enough, because users will still be able to edit it if they really want. You should use $element->setIgnore(true) that will ensure that Zend_Form_Element won't try to populate the element from POST/GET, and I'd double check that also. You have to make sure the values you are getting into the databases can never contain this element.
Finally, if you would like your element to be displayed in a different way than just with readonly, you can do that by changing the element decorators.
I just managed to work this one out myself. The solution was to change the view helper on the elements to the formNote helper eg. $element->helper = 'formNote'. The result of this was that the value gets displayed as straight text instead of being inside a form element.
Thanks for your answers.
That's very good solution when you don't need to populate the element value when the form is submitted.
It's equivalent solution is to use the Form Element method setAttrib() and disable the form element
$formElement->setAttrib('disable','disable')
which will only freeze the element.
But if you need to populate the field, using the previous solutions you will probably need additional hidden field added, which will pass the value. Developing custom form element will be good style but that's not welcomed by each developer so you can use some tricky way to set a form element as a text only but populate its value. That way is when you create the element as a hidden field, set its value and use the Form Element method setDescription() to set and display the element text value.
$formElement = new Zend_Form_Element_Hidden( 'elName',
array( 'label' => 'elLabel', 'value' => 'elValue' ) );
$formElement->setDescription( 'elValue' );
Then you can render that hidden element and display the value with the
$formElement->getDescription().
$element->setAttrib('readonly', 'true');
http://www.w3.org/TR/html401/interact/forms.html#adef-readonly
According to Amr Mostafa, if you use:
$element->setAttrib('readonly', 'true');
OR
$element->setAttribs(array('disabled' => 'disabled'));
User still send values by POST/GET and they are stored in DB.
The only way for me to don't taking into account the values from POST/GES is:
$element->setIgnore(true)
Example:
$element = new Zend_Form_Element_Text('element');
$element->setIgnore(true);

Categories