I am trying to click a radio button by using Perl with Mechanize module . I tried
$mech->find_all_inputs ( name => "name" , value => "1" )
, but could not get any result. The html code of the radio button is like that;
<input name="name" value="1" type="radio">
And there are other radio buttons with the same name but different values.So how can I click the radio button using Mechanize module?
Thank you in advance.
The user agent cannot magically distinguish the right one. Find them all, and then go through them and pick the one(s) you need. You can learn values by the method possible_values
# Finding the field name and values for the radio element
foreach ( $ua->find_all_inputs(type => 'radio') ) {
$radio_name = $_->name;
say "$radio_name values: " . join('|', $_->possible_values)
}
If it's just one
my ($radio_name, $input_err) =
map $_->name, $ua->find_all_inputs(type => 'radio');
warn "More radio inputs than expected: $!" if defined($input_err);
Once you have the right button you can fill the form in which it is. For example
$ua->submit_form( fields => { $radio_name => 'AND' });
The submit_form "lets you select a form from the previously fetched page, fill in its fields, and submit it." [from docs, WWW::Mechanize]. It takes parameters as hashes, where you can set names and values, for example. This method is a higher-level wrapper, instead of which you can use more specific ones, for example
$ua->field( $name, $value );
To set a field among duplicate ones, pick the number of the one you want. For example, to set the second one from the list
$ua->set_fields( $name => [ 'field_value', 2 ] )
Also note that WWW::Mechanize inherits heavily. When you search for the right call it may be a good idea to look through methods in the packages that it inherits from.
Related
I can populate a gravity form text field that has a parameter name of 'textfield' with a query string like
https://www.example.com/formpage/?textfield=value
But I would also like to be able to populate a checkbox, i.e check a box. However, checkboxes are not mentioned in the Gravity Forms documentation "Dynamically Populating a Field".
My checkbox is called 'flags' and has choices with names of 'box1' and 'box2', so I tried
https://www.example.com/formpage/?textfield=value&flags.box1=true
https://www.example.com/formpage/?textfield=value&flags.box1=1
https://www.example.com/formpage/?textfield=value&flags[box1]=true
https://www.example.com/formpage/?textfield=value&flags[box1]=1
https://www.example.com/formpage/?textfield=value&flags=box1
But I cannot get a box to check. Does anyone know if there is a way to do this?
Went and looked at the code.
To set a single checkbox (or value in a list) use
https://www.example.com/formpage/?textfield=value&flags=box1
To set multiple values the code is set up to use syntax like:
https://www.example.com/formpage/?textfield=value&flags=box1|box2
https://www.example.com/formpage/?textfield=value&flags=box1%C7box2
However, in the gravity form source there is a test for a list, that also needs to test for a checkbox. In forms_model.php, function get_parameter_value I changed the statement
if ( ! empty( $value ) && RGFormsModel::get_input_type( $field ) == 'list' )
to
if ( ! empty( $value ) && (RGFormsModel::get_input_type( $field ) == 'list' ||
RGFormsModel::get_input_type( $field ) == 'checkbox' ))
Then it all works!
Your syntax was just a bit off. It's not that well documented. You need to use commas.
https://www.example.com/formpage/?textfield=value&flags=box1,box2
I want to build a multipage from.
The first page asks for first name and last name.
I want to greet the user with his first name in the second page.
The best way to do this is to use Live Merge Tags with Populate Anything:
https://gravitywiz.com/documentation/gravity-forms-populate-anything/#live-merge-tags
If you collected the user's first name in a Name field on page 1, you could great him in the field label for a field on page 2 like so:
Hello, #{Name (First):1.3}
(In this example, the field ID for the Name field is 1. The 3 refers to the first name input of a Name field and will always be 3).
If avoiding another plugin (as useful as that one is), you can use either the pre_submission_filter or pre_submission hooks to do this.
If their name was field 1 and lets say the field you'd like to show is field 2...
// THESE FOUR FILTERS WORK TOGETHER TO PRE-POPULATE ALL SORTS OF STUFF, AND YOU CAN ADD TO THIS AS NECESSARY. MINE IS ABOUT 1500 LINES LONG AND IS USED BY SEVERAL FORMS.
add_filter('gform_pre_render', 'populate_forms');
add_filter('gform_pre_validation', 'populate_forms');
add_filter('gform_pre_submission_filter', 'populate_forms', 10);
add_filter('gform_admin_pre_render', 'populate_forms');
function populate_forms($form) {
$form_id = $form['id'];
$current_form = 2; // pretending the form id you are working on is 2.
$future_form = 10; // imaginary form you'll create later for another purpose.
switch($form_id) {
case $current_form:
$first_name = !empty(rgpost('input_1_3')) ? rgpost('input_1_3') : null; // gets the value they entered into the first-name box of field 1.
foreach ($form['fields'] as &$field) {
if ($field->id === '2') { // Make as many of these as necessary.
if ($first_name) { // make sure there's actually a value provided from field 1.
$field->placeholder = $first_name; // not necessary, just habit since sometimes you'd need to have a placeholder to reliably populate some fields.
$field->defaultValue = $first_name; // this is the piece that will actually fill in the value like you'd expect to see in your question.
}
}
}
break;
//case $future_form: do more stuff.
//break;
}
return $form;
}
That should be a decent start for your functionality plugin where you can populate the current and future forms without much hassle. This can also be done with the gform_field_value hook; I've always found the language a bit clumsy with that one, personally.
The plugin mentioned earlier is definitely neat, but I found myself wanting to rely on that stuff less and less.
I created a new EAV attribute using this code :
'information',
[
'type' => 'int',
'default' => null,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => false
]
this attribute is by default hidden, but I want to visible it after a condition, is there any method to do that?
The visibility of the attribute is set per global or store view, so this should not be possible. However, when you display your attribute, for example on your product view page, you can build in some logic to decide wether it should be displayed or not.
Solution 1
Here's an example I used in a similar way in phtml on product view:
<?php
$product = $block->getProduct();
$attribute = $product->getResource()->getAttribute('attribute_code')->getFrontend()->getLabel($product);
if('>>your_condition_here<<'){
echo $_attribute;
}
?>
You could use this anywhere you want, especially outside of the details tab.
Solution 2
Another way would be to extend the default detail tab and build in your condition. Copy vendor/magento/module-catalog/Block/Product/View/Attributes.php to your module or theme and extend the first if condition (line 83)* in getAddtionalData() to your needs.
Change
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr))
To
if (($attribute->getIsVisibleOnFront() || ($attribute->getAttributeCode() == 'information' && '>>>your condition here <<<')) && !in_array($attribute->getAttributeCode(), $excludeAttr))
*I should add that this works for M2 2.2.x. I don't know about 2.3
I wanted to know if there's a way to customize the select option from the subpanel men in Suitecrm.
All one-to-many relationships for a module's subpanel are to be removed whereas for many to many need to rename it to "Associate Module 1 to Module 2 ".
Can I achieve this and this is to be done for all modules.
To remove buttons:
Assume that Target module and Lead module has one to many Relationshipship. Now Leads will be shown under the Traget Record Detailview. So if we want to remove selection and creation of Lead from Subpanel of Lead. Then we can hide this two buttons from following code:
Find The relation ship file in
custom/Extension/modules/Prospects/Ext/Layoutdefs/prospects_leads_1_Prospects.php
Remove Commented code as commented in this relationship code as Below,
And then Repair and Rebuild.
$layout_defs[“Prospects”][“subpanel_setup”][‘prospects_leads_1’] = array (
‘order’ => 100,
‘module’ => ‘Leads’,
‘subpanel_name’ => ‘default’,
‘sort_order’ => ‘asc’,
‘sort_by’ => ‘id’,
‘title_key’ => ‘LBL_PROSPECTS_LEADS_1_FROM_LEADS_TITLE’,
‘get_subpanel_data’ => ‘prospects_leads_1’,
‘top_buttons’ =>
array (
/*
0 =>
array (
‘widget_class’ => ‘SubPanelTopButtonQuickCreate’,
),
1 =>
array (
‘widget_class’ => ‘SubPanelTopSelectButton’,
‘mode’ => ‘MultiSelect’,
),
*/
),
);
moreover, you can check labelvalue and then change label in language file accordingly.
To Rename button at system level:
Place following language label in custom/include/language/en_us.lang.php
$GLOBALS['app_strings']['LBL_SELECT_BUTTON_LABEL'] = 'your label';
This will change the label for all but if you want to change it via some logic then see file: include\generic\SugarWidgets\SugarWidgetSubPanelTopSelectButton.php, it has public function getDisplayName() where you can add some logic to change that label in a specific condition. Hopefully, you will write that logic your own. Also, you can return empty html in those cases where you don't need button.
I have a form, created with Zend_Form, with method = GET used for searching records with elements as below:
[form]
user name [input type="text" name="uname"]
[input type="submit" value="Search" name="search"]
[/form]
After form is submitted all the GET parameters along with submit button value are appearing in the url.
http://mysite.com/users/search?uname=abc&search=Search
How to avoid submit button value appearing in the url? is custom routing the solution ?
When you create your element, you can simply remove the name attribute that was automatically set at creation
$submit = new Zend_Form_Element_Submit('search')->setAttrib('name', '');
Or inside a Zend_Form
// Input element
$submit = $this->createElement('submit', 'search')->setAttrib('name', '');
// Or Button element
$submit = $this->createElement('button', 'search')->setAttribs(array
(
'name' => '', 'type' => 'submit',
);
When a form gets submitted, all of its elements with their names and values become a part of a GET / POST - query.
So, if you don't want an element to appear in your GET - query, all you need to do is to create this element without a name. That's probably not the best approach, but since we're talking about the 'submit' element, I guess it doesn't matter that much.
Looking at Zend_View_Helper_FormSubmit helper, you can see that it's creating the 'submit' element and setting its name. So, the possible solution would be to create your own view helper and use it for rendering the 'submit' element instead of the default helper.
You can set a custom helper with
$element->setAttribs( array('helper' => 'My_Helper_FormSubmit') );
Then build your own form element class and remove the name attribute from the element with preg_replace. The beauty of it is, it will not interfere with the other decorators.
So the something like this:
class My_Button extends Zend_Form_Element_Submit
{
public function render()
{
return preg_replace('/(<input.*?)( name="[^"]*")([^>]*>)/', "$1$3", parent::render(), 1);
}
}
You can remove name attribute for submit button in javascript.
jQuery example:
$('input[name="submit"]').removeAttr('name');
In the controller that represents the form's action, redirect to another (or the same controller) only including the relevant params.
Pseudocode:
$params = $this->getRequest()->getParams();
if isset($params['search'])
unset($params['search']);
return $this->_helper->Redirector->setGotoSimple('thisAction', null, null, $params);
handle form here
This is basically the same idea as Post/Redirect/Get except that you want to modify the request (by unsetting a parameter) in between the different stages, instead of doing something persistent (the images on that Wiki-page shows inserting data into a database).
If I were you, I would leave it in. IMO it's not worth an extra request to the webserver.