Is it possible via some sort of Hook or Filter to change the "name" attribute on a form element in Gravity Forms? It allows you to select "Allow field to be populated dynamically" and then set a "Parameter Name", however the parameter name doesn't match up with the element's name attribute. My element's names are like input_6_1 or something.
I'm trying to avoid using jQuery to accomplish this, but I suppose I will resort to it as a last resort. Any ideas?
It isn't the most beutiful code, and I'm not sure if there is a gravity forms approved way (it wasn't apparent to me), but something like this should work for you.
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#input_1').attr('name','YOURCUSTOMNAMEVALU');
});
</script>
Also, for WordPress you should probably wrap it in a scope to contain this to the page that contains your form.
Something like
<?php
if(is_page('forms-page') && !is_admin()) {
?>
//Javascript Here
<?php } ?>
For style points you can use enqueue_script to include it from your functions.php
Set the parameter name to something like 'customparam'.
Then dynamically populate it using a filter.
add_filter('gform_field_value_customparam', 'populate_customparam');
function populate_customparam($value){
return 'Hello';
}
This will dynamically insert 'Hello' into every gravity form field with parameter named 'customparam'
Related
I'm looking for a way to have a button toggeling the field of my form. When "locking" the form with the toggle button no data can be typed. When "unlocking" data should be allowed to be typed. What I want to achieve with this is simple avoiding users to accidentally type.
I found the code below and it works. Only problem is that it only applies to one input field. I want it to work on more that one.
<input type="checkbox" id="yourBox">
<input type="text" id="yourText">
<script>
document.getElementById('yourBox').onchange = function() {
document.getElementById('yourText').disabled = this.checked;
};
</script>
Mark the fields you want to disable with a CSS class, and then use jQuery to disable them.
jQuery - Disable Form Fields
If you want a pure Javascript solution, just repeat this line
document.getElementById('yourText').disabled = this.checked;
for each field.
Or, you can do something like this this: How to Get Element By Class in JavaScript?. Note that you can assign multiple CSS classes to the same field, so assign another class to identify those fields that need to be disabled.
I want to be able to format a field in Joomla. I'm creating a form that has a number of inputs and I want to format the inputs to have a yellow background and be of various lengths. Currently my form is produced in the standard Joomla way:
<div class="tablecol1">
<?php echo $this->form->getLabel('dob'); ?>:
</div>
<div class="tablecol2">
<?php echo $this->form->getInput('dob'); ?>
</div>
I've looked through the JForm stuff but I can't figure out how to control the format of the generated input box?
help would be great thanks
Setting a class for the inputs would be the quickest and easiest way as mentioned by MasterAM. You can then style it however you wish using CSS.
If you need to change the HTML or particular attributes that are not possible to set through the default parameters, then the next option is to create your own field type.
You can either override the existing ones or create ones with new names. For example you could copy the checkbox field (/library/joomla/form/fields/checkbox.php) into your own folder (/components/com_mycomponent/form/fields).
If you leave it as JFormFieldCheckbox it will override the default one. If you rename it - e.g. JFormFieldCustomCheckbox then you can have your own one.
The primary function you will want to look at is getInput(). This generates the HTML and will let you create your own input html with whatever attributes you wish.
To use custom attributes/settings from your form xml file, in your getInput() function you will use something like:
$fieldsize = $this->element['field_size'];
I would like to overwrite a form by creating a custom module. But therefor, I need to get a hold to my form ID in the function.
Drupal.org mentionned the hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) function, but when I apply this to my form, it doesn't respond. Do I have a syntax error when I use following statement?:
function redactie_omgeving_fiche_node_form__form_alter(&$form, $form_state, $form_id) {
echo(var_dump('ONZE redactie_omgeving__fiche_node_form__form_alter'));
}
and this is my form:
<form class="node-form node-fiche-form" enctype="multipart/form-data" action="/node/1/edit" method="post" id="fiche-node-form" accept-charset="UTF-8">
A nice little trick to make sure you have the right form id is to first use hook_form_alter() to get the form id, then use hook_form_FORM_ID_alter(). For example, use:
function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
drupal_set_message($form_id);
}
to see a Drupal message of all form id's on the current page. Once you have the correct id, then place it into hook_form_FORM_ID_alter(). Try that and make sure you are using the right form id.
Im trying to preserve the user inputs from dynamic menu dropdown lists - I have an number of drowpdowns and a user input text field , when the user submits the form after selecting the options from the dropdowns.
I would like to be able to preserve the last choices made so the user does not have to reselect the options again when re posting the form with another value in the text field, i would also like this to work on errors as well ?
Im using ZF to validate the form.
i have tried the follwing code in the value attr of the option:
<option value="<?php if ($_POST && errors) {
echo htmlentities($_POST['CategoryID'], ENT_COMPAT, 'UTF-8');
}?>">Main Category</option>
But does not seem to work ?
I have a static options "Main Category" ect. which is what the form defaults to after submiting
can anyone help me on this one ??
Thanks in advance
I would highly recommend using Zend_Form. If that is not possible, I would next use Zend_View Helpers to build your HTML manually. Then you can use the formSelect in your view like this:
echo $this->formSelect('CategoryId', $selected, $attribs, array(
'main' => 'Main Category'
// ... other options
));
Where $selected variable equals to one of the following: posted value(s), default value(s), or is null and $attribs variable is simply attributes for the select element.
I have a form that will have dynamically created elements, one of those will be of date type. There can also be many fields of this type on my form, all which must be validated.
I am using a strongly typed view in Asp MVC, so the name will change based on various factors. What I would like to do is validate based on a class name instead, since that will be constant for that type of field.
Ie:
<%= Html.TextBox("questionAnswers[" + index + "].AnswerValue", qa.AnswerValue, new { #class = "DateTypeClass" })%>
So then I would need JQuery validation based on the classname DateTypeClass versus the Name.
Any ideas?
In your validation function you could check the value like so:
var dateFieldValue = $(".DateTypeClass").val();
//validate dateFieldValue here
Also you don't have to resort to selecting by class if you don't want to. If no other fields share this validation then you could select by partial id in jquery. That would look like this:
var dateFieldValue = $("[id^=someId]").val();
//validate dateFieldValue here
So you would if set someId on the field and ASP.Net adds some additional stuff to the id it will still select it properly. I don't use ASP.Net MVC so not sure where you are setting the ID (if at all)
Also if you want inline validation you can wireup the onBlur event like so:
$(".DateTypeClass").blur(function(){
//Call field validation function here
});