how do i make diffrent registration form in drupal? - drupal-6

Is there a module that can make different registration forms for different roles during sign up? (ex. each Editor,Main User,Sub User role have different form)

Here's what you should do
start with install profile2-7.x-1.2.tar.gz.
entity-7.x-1.0-rc3.tar.gz once you have profile2 installed -->
enable --> click on configure - (Here you see your profile types
-add as many as you want).
when you add a new one or modify the existing one "Main" make sure you check "Provide a separate page for editing profiles."
4. Now to have different registration, login and password change pages
install and enable profile2_regpath-7.x-1.9.tar.gz
Now visit the profile Types Page again here you should see "UNIQUE REGISTRATION PATH" .. rest is easy ..

There is :)
http://drupal.org/project/autoassignrole
to assign by path you will also need Content Profile:
http://drupal.org/project/content_profile
check out this tutorial on how to pull it off:
http://www.web-a-team.com/blog-post/user-registration-more-one-role

Here is some idea how to solve your question in drupal 7(I think it should work in drupal 6 also). However its not safe since anyone can just change the role they have:
function my_module_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$company_role = $form_state['build_info']['args'][0];
$form['account']['company_role'] = array(
'#type' => 'select',
'#title' => t('Company role'),
'#options' => drupal_map_assoc(array('editor','main user','Sub User')),
'#description' => t('Please select your company role'),
"#empty_option" =>t('- Select -'),
'#weight' => -11, // Add the select box above username that have weight -10
);
switch (strtolower($company_role)) {
case 'editor':
// add extra fields for editor
$form['account']['company_role']['#default_value'] = $company_role;
break;
case 'main user':
// add extra fields for main
$form['account']['company_role']['#default_value'] = $company_role;
case 'sub user';
// add extra fields for 'Sub User'
$form['account']['company_role']['#default_value'] = $company_role;
break;
default:
$form['account']['company_role']['#empty_option'] = t('- Select -');
$company_role = null;// error handling or default case
}
}
If you for example have LDAP in your company you could instead get this information from LDAP(https://www.drupal.org/node/1053748). Then you can be more sure about the role is chosen correctly.

Related

How to add data into Stripe during the testing my site in Cypress

I'll try to explain my problem.
I do test on the site - mysite.com. But during the registration user should add credit card data. They can do it on https://checkout.stripe.com/pay.
This page is opened after click on Next button.
How can I add credit card data?
THanks
Go to cypress/support/commands.js and create a custom command like this.
Cypress.Commands.add('getStripeElement', (selector, value) => {
cy.get('iframe')
.should((iframe) => expect(iframe.contents().find(selector)).to.exist)
.then((iframe) => cy.wrap(iframe.contents().find(selector)))
.within((input) => {
cy.wrap(input).should('not.be.disabled').clear().type(value)
})
})
And then in your tests, you can add this:
cy.getStripeElement(
'input[data-elements-stable-field-name="cardNumber"]',
'4444222211110000'
)
cy.getStripeElement(
'input[data-elements-stable-field-name="cardExpiry"]',
'1025'
)
cy.getStripeElement('input[data-elements-stable-field-name="cardCvc"]', '123')
cy.getStripeElement(
'input[data-elements-stable-field-name="postalCode"]',
'90210'
)
Alternatively, there is a 3rd party plugin which provides the same custom command code as the one provided by Das.
https://github.com/dbalatero/cypress-plugin-stripe-elements

shopware 6: how can I get a price rule ID at updating productrepository

I have a question about programmatically updating a product via the Shopware 6 ProductRepository. I will update actionprices for my product.
But then rule Id is a required field. But how can I get this Rule ID field?
$price = [[
'linked' => false,
'net' => (float)$netPrice,
'gross' => (float)$grossPrice,
'currencyId' => Defaults::CURRENCY,
]];
$prices = [
[
'quantityStart' => 1,
'ruleId' => '???', // How can I get this???
'quantityEnd' => 10,
'price' => [
[
'currencyId' => Defaults::CURRENCY,
'gross' => $actionGrossPrice,
'net' => $actionNetPrice,,
'linked' => false
]
]
]
];
So how can I get this rule ID field?
Unfortunately you did not post the full code, especially the portion where you call the update function. I am assuming, that you are trying to set the "advanced pricing" of a product.
Before doing something programmatically, it might be a good idea to check how it's done manually.
In the admin panel (Shopware v6.4.3.0), creating advanced price rules also needs a rule id:
This refers to a rule created before unter Settings -> Shop -> Rule Builder.
There are some rules created by default, for example "all customers":
You can pick the rule ID from the URL when clicking that rule and use this in your code.
This might be fine if you write a plugin for one specific shop. But the rule would differ in other shops.
In case you are writing a plugin for a broader audience, I recommend to make the rule to be applied configurable in the plugin configuration.
You could of course also search programmatically for a rule "All customers" - but it might have been deleted by the shop owner.

Drupal 8 Custom module - how to create a field in the admin area, and then pull that input in my module to use?

New to Drupal 8, I'm coming from the WP world so it's been very confusing getting the hang of things. I created a custom module and have a page outputting text. Where I'm stuck is the ability to make a field in the admin area, pull that saved info, and then use it in my content that's being output.
Been following along with tutorial but am very stuck. Can anyone provide a road map for me or helpful articles to accomplish this?
Suppose your module name is "custom" then follow these steps to create a admin form and pull the saved info on admin page.
Create a folder name "custom".
Create "custom.info.yml" file within "custom" folder.
name: custom
description: Show admin saved data through custom module.
type: module
# core: 8.x
configure: admin/config/services/custom
Create a Permission for who access admin form.
For Permission create "custom.permissions.yml" file within "custom" folder.
'administer custom':
'title': 'Administer Customform'
'description': 'Configure how Custom Form is used on the site.'
restrict access: true
Then create a route for custom admin form path & it's content.
Create "custom.routing.yml" file within "custom" folder.
custom.config:
path: '/admin/config/custom/config'
defaults:
_form: '\Drupal\custom\Form\CustomConfigForm'
_title: 'Custom Configuration'
requirements:
_permission: 'administer custom'
Now create a menu and assign this route ("custom.config") in menu path & create a form within custom folder and the form location is
src/Form/CustomConfigForm.php
For menu create a "custom.links.menu.yml" file within "custom" folder.
custom.config:
title: 'Custom '
description: 'Custom Admin Configuration'
parent: system.admin_config
route_name: custom.config
weight: 100
For admin form create CustomConfigForm.php file within custom folder and the file location is src/Form/CustomConfigForm.php
<?php
namespace Drupal\custom\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CustomConfigForm extends ConfigFormBase {
public function getFormId() {
return 'custom_config_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom.settings'); // store data in custom.settings
$form = parent::buildForm($form, $form_state);
$form['custom_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content Types'),
'#description' => t('Configure where the custom button should appear.'),
'#options' => node_type_get_names(),
'#default_value' => $config->get('custom_types', array()),
);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom.settings');
$config->set('custom_types', $form_state->getValue('custom_types'));
$config->save(); // save data in custom.settings
return parent::submitForm($form, $form_state);
}
public function getEditableConfigNames() {
return ['custom.settings'];
}
}
Now when you save admin form then after you fetch the saved data in "custom.module" file to use this code.
Create "custom.module" file within custom folder.
$config = \Drupal::config('custom.settings'); // get saved settings
$types = $config->get('custom_types', array()); // fetch particular saved data "custom_types"
print $types;
Now enable this module.
Your admin form path is YOUR_SITE_NAME/admin/config/custom/config
Also in Drupal 8 sometimes cache problem occurs, so if any problem comes then clear the cache after form save.

use drupal hook_nodeapi

i have a page tweety which contains a single form where a user enters a word in a textbox and in on pressing search the tweets corresponding to that word are displayed.
I want to use hook_nodeapi to add these tweets but i want those things only on a specific url not all the page(or any node type).
I ll use hook_menu to make that page and display the form for the search. What should i do after that. I knw the twiiter api to fetch the tweets so that is not a issue.
I think what you're attempting to do is have the tweets load on a predetermined page by passing the posted information to the page, is that correct?
There's a couple ways I think you could accomplish this - easiest, and not requiring any complex ahah scripting would be to take the word they enter and generate a path which you could then use to make the page in question.
Make a menu Item:
function mymodule_menu() {
$items = array();
$items['mymodule/tweets/%'] = array(
'title' => t('Tweets about' . check_plain(array(2))),
'page callback' => 'mymodule_tweet_display',
'page arguments' => array(2) // This is the 3rd argument in the path, the %
);
}
In your form, you'll need to send the user to this path so add to your hook_submit function:
$tweet_topic = $form_state['values']['your-field-name-here'];
drupal_goto('mymodule/tweets/' . $tweet_topic);
Now add your page module, this is where you can use the twitter api:
function mymodule_tweet_display($tweet_topic) {
$tweet_topic = check_plain($tweet_topic);
// Use this variable in your Twitter API call
// ...
// Make sure you assign your display content to the page by returning a variable
return $page;
}

Sharepoint web part form validation blocks updating web part settings

I have written a web part in C# for Sharepoint 2007 which has a single field which is validated as a required field using RequiredFieldValidator(). The web part also has some configuration fields (ones you edit by clicking on Modify Shared Web Part).
When I make changes to these fields and try to apply them, the validation of the user field kicks in and prevents the update, even though I am not submitting the form. I am only trying to submit the settings. The web part may be used in a few places on our farm, so site collection administrators need to be able to change the settings - at the moment it is not friendly enough for these users to do so.
Here is where I validate the user field:
// Validate form field - required field, and max length is 100 characters.
InputFormRequiredFieldValidator messageRequiredValidator = new InputFormRequiredFieldValidator();
messageRequiredValidator.ControlToValidate = txtMessage.ID;
messageRequiredValidator.ErrorMessage = "You must write a message to send!";
messageRequiredValidator.Display = ValidatorDisplay.Dynamic;
messageRequiredValidator.Text = "<img src=\"/_layouts/images/CNSCA16.gif\"/> You must write a message to send.";
tc.Controls.Add(messageRequiredValidator);
Here is where I define one of the configuration fields:
private string recipientEmailAddress = "sender#domain.tld";
[WebBrowsable(true),
Personalizable(true),
WebPartStorage(Storage.Shared),
WebDescription("Email address the form should be sent to"),
WebDisplayName("Recipient Email Address"),
SPWebCategoryName("Email Settings")]
public string RecipientEmailAddress
{
get { return recipientEmailAddress; }
set { recipientEmailAddress = value; }
}
This is the first web part I have written, so there may be some subtleties I am missing in how to do admin configuration and validation of user submitted fields.
Ok - I've found the key to this. You can add a validationGroup property to each validator, and to the button that causes the validation. So I changed my code to include:
messageRequiredValidator.validationGroup = "UserInput";
and a similar property to my submit button. Now when I click on Ok in the ToolPane, it doesn't validate the UserInput validation group. That only happens when I click on my Submit button.
You can dynamically disable validations on OK, Cancel buttons in ApplyChanges method:
ToolPane pane = Zone as ToolPane;
if (pane != null)
pane.Cancel.CausesValidation = false;
OR you can also check if editor pane is open and disable validation in webpart :
WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(Page);
if (wpm.DisplayMode == WebPartManager.EditDisplayMode)
{
//Page is in edit mode
}
I would suggest to use the SharePoint validation control.

Resources