Set form value from url parameter - typo3

I am using Typo3 10LTS and I would like to set the value of a form field with a parameter value from the URL.
E.g. the value "123" should be entered into the form field "field-1" via the URL www.test-xyz.de/sidename?field-1=123.
Thanks,
Stephan

Fluid
Let's say we have a fluid link, with parameter "123"
<f:link.page pageUid="999" additionalParams="{param: '123'}" noCacheHash="true">Link to Form</f:link.page>
This sends the parameter to the page with the form, containing the value in the URL:
www.test-xyz.de/sitename?param=123
See: link.page Documentation
jQuery
We can now use a few lines of jQuery to populate a field with the value from the URL:
$(".myForm").each(function() {
// Function to sanitize output
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
};
// Populate the input field '.field1' with the parameter in the URL
if (getURLParameter('param') !== null) {
var value = getURLParameter('param');
$('.field1').each(function(){
$(this).val(value);
});
};
});

Related

gravity forms Form Entry - display label, not value for checkboxes, select

I've got checkboxes and selects where label is different to its value.
In the DB the value is saved ok, however, when viewing Form Entries (and pre-submit form data) for all the checkboxes and selects the values are displayed not labels. So I end up with not so informative IDs rather than names.
Is there a way to display labels instead of values in the Form Entries screen?
I came across your question while looking to do the same thing. I have a field called Account Type that stores the account type ID as the value. In the entries list I want to show the account type name, not the ID.
Here's the solution:
In your theme's functions.php file add the following filter:
add_filter( 'gform_entries_column_filter', 'modify_entry_view', 10, 5 );
You'll find the documentation for it here: https://docs.gravityforms.com/gform_entries_column_filter/
Then add the function code:
function modify_entry_view( $value, $form_id, $field_id, $entry, $query_string ){
//- Check the field ID to make sure you only change that one
if( $field_id == 14 ){
return 'modified value';
};
return $value;
}
In my case I'm using a custom field that I created called account_type that prepopulates a select menu with choices corresponding to each of the account types in our system. I used the following call to check the field type instead of checking based on field id since the id will change from form to form:
if( RGFormsModel::get_field( $form_id, $field_id )->type == 'account_type' ){
You could do the same thing but use the label property instead of type, like:
if( RGFormsModel::get_field( $form_id, $field_id )->label == 'Field Label' ){
In my case the value saved is a term id from a custom taxonomy I set up called account_type, so I simply use:
return get_term_by( 'id', $value, 'account_type' )->name;
to replace the account id with the account name.
FYI: The process is the same for the entry detail, use the filter documented here: https://docs.gravityforms.com/gform_entry_field_value/

Wordpress GravityForm autosubmit with a parameter

I have a requirement to auto-submit a GravityForm with a form parameter. So, as far as I know GravityForms has the ability for you to send a parameter through the URL and it'll automatically fill out a field for you. What I want to do is the ability to send another field called autosubmit=true in which if that is on there, it will automatically submit the form.
Here is a generic solution for any form: Automatically submit a form
And here is a Gravity Forms specific solution: https://www.gravityhelp.com/forums/topic/autosubmit-with-gravity-forms
The basic premise of both is that you use Javascript to trigger the form submission when the page loads. You would need to make yours conditional so that it checks the value of your pre-populated autosubmit field.
<script>
jQuery( document ).ready( function() {
// Update "1" to your form ID and "2" to your prepop field ID
if( jQuery( '#input_1_2' ) == 1 ) {
// Update "1" to your form ID
jQuery( 'form#gform_1' ).trigger( 'submit' );
}
} );
</script>

Select/Get html node from an element using D3

Let's say I have an html object called element that I create using bellow code:
var xmlString = "<div class="parent"><span class="child"></span></div>"
parser = new DOMParser()
var element = parser.parseFromString(xmlString, "text/xml");
// or simply using jquery
var string = "<div class="parent"><span class="child"></span></div>"
var element = $(string);
What I want to do is to select span.child from element using D3, not from the document. Using d3.select('span.child') will try to look for the <span class="child"></span> in the html document.
I checked the documentation and it says:
A selection is an array of elements pulled from the current document.
But I want to select not from the document but from the above element that I just created. Is there any way?
After a bit of debugging I found out that if element is a object, not string, then d3.select(element) will not look for the element in the document instead it will return the element itself.
for detailed info:
d3.select = function(node) {
var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
group.parentNode = d3_documentElement;
return d3_selection([ group ]);
};

Yii2 REST API fields (user?fields=id) does not work

I've got the REST API working with the user table provided in the base migration. I can "GET /users" just fine, but according to the docs, I should also be able to "GET /users?fields=id" and receive a response limited to the id fields.
But instead I get the full result set.
Under the topic Fields in Yii2 Guide it says;
// only returns field id and email, provided they are declared in fields()
http://localhost/users?fields=id,email
so you have to override the fields() function to get the expected result.
// explicitly list every field, best used when you want to make sure the changes
// in your DB table or model attributes do not cause your field changes (to keep API backward compatibility).
public function fields()
{
return [
// field name is the same as the attribute name
'id',
// field name is "email", the corresponding attribute name is "email_address"
'email' => 'email_address',
// field name is "name", its value is defined by a PHP callback
'name' => function ($model) {
return $model->first_name . ' ' . $model->last_name;
},
];
}

How to use fetch with with sending the Id

Hi I have the next model in backboneJS:
var Type = Backbone.Model.extend({
url : "/api/SomeRoute"
});
var model = new Type({id:"MyAlias"});
model.fetch();
On the rest part In SomeRoute I have 2 actions which returns my Model. First which recieves the Id and returns the Model by Id and second without parameters which return the collection. But when I call fetch() in JS, it doesn't send the Id in the request. What I'm doing wrong?
If there is an id attribute specified in a model. Then the fetch request will be like /api/SomeROute/id
Instead of url give urlRoot. If urlRoot is specified then the models id will be appended.
var Type = Backbone.Model.extend({
urlRoot : "/api/SomeRoute"
});
Rewrite your url to next:
var type = Backbone.Model.extend({
url: function(){
return "/api/SomeRoute/" + this.get("id");
}
});
var model = new Type({id: "SomeId"});
model.fetch();