How to make the roles radio button mandatory in the register form. drupal 8 - forms

I have Drupal 8 site and I’m using the Select registration roles module to allow the user to choose its role during the registration process. and It works fine. but I want to make it mandatory to choose from the radio buttons.
any idea how to do that?
Thanks in advance.

For making it required, we can alter the form using hook_form_alter() inside .module file.
Add the following code.
if ($form_id == "user_register_form") {
$form['select_roles']['#required'] = TRUE;
}

Related

React native form

I'm very new to react-native and I'm having trouble of what things to use.
I'm building an app in which I need to login or register. For now I just want to use a form, when I fill it submits datas to my api and get logged. I don't know what kind of form component I should use, there seem to be different component to install and use, I need some advice 'cause I'm a little bit lost.
Thanks in advance
I highly recommend you redux-form along with react-native-elements or nativebase
You can use tcomb-form-native.It simplifies creating a form.
Well to code it from scratch you need 2 textInput one for the username or email and the other for password and a button or touchableOpacity for Login or signUp button. and authfunction which is the function to certify the credentials. In your APP file you check wether the user is authenticated or no and display the next screen you can use redux to pass data around but I will make it simple here and use AsyncStorage to Authenticate the user let me know if you need it.
import React,{Component,useState} from ‘react’;
import {TextInput,Text,SafeAreaView,StyleSheet, Button} from ‘react-native’
export default function Login = () => { [username,setUsername]=useState();
[password,setPassword]=useState();
return(
setUsername(val)} />
setPassword(val)} />
authfunction(username,password)} />
);
}

Drupal 7 Webform redirect

We have a Drupal 7 webform that redirects to a url upon successful submission.
What we need to do is redirect the user if they land on the same webform again and have already submitted.
Do we need a module for this, or do it programmatically?
Thanks in advance.
I looked through the webform module and didn't find any setting that will redirect the user if the user has already submitted a form, so I think you need to do it programmatically.
Note: It might be possible without a custom module by using the rules module. I haven't tried this.
To do it programmatically you could do something like below. It implements the hook_node_view() and checks if the user has already submitted anything by using the webform api function webform_get_submission_count(). (edit: the custom module in this example is called example_webform)
<?php
/**
* Implements hook_node_view().
*/
function example_webform_node_view($node, $view_mode, $langcode) {
global $user;
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission_count = webform_get_submission_count($node->nid, $user->uid);
if (!empty($submission_count) && $submission_count > 0) {
$redirect = $node->webform['redirect_url'];
drupal_goto($redirect);
}
}
As it is now it will reuse the page that is used when the form is submitted, so if you choose to do this remember to make the success page reflect this. (E.g. it would be strange for the success page to say "your post has been saved" if the user lands on it for the second time.) Or you could replace the $redirect with another page than the one from the webform setting.
Also note that the webform will still add the message "You have already submitted this form. View your previous submissions." if this is enabled.
So here is the solution that we ended up going with.
I saved the webform and made it available as a block
I created a page to hold the webform
I configured the block to appear above the page content
In the page content I put in some javascript to detect if the form element was present - if not forward to the correct url
So the webform redirects correctly upon submission(set in the webform settings), and it then redirects if the user lands back on that page and has completed the webform.

how to assign specific user roles upon automatic registration - simple FB Connect - Drupal 7

How do I assign a specific role from drupal core(D7) upon automatic registration with Simple FB Connect? I currently am using auto role assign and have a custom registration for 2 roles, One is a basic role with limited permissions and the other an advanced role with more edit/creation permissions. My problem is that the simple FB connect link works great but is registering people for the wrong roles. How can I choose the role that is being assigned based on the url?
Maybe something in template.php that would allow the following url to be placed on my facebook buttons?
/user/simple-fb-connect?registration=1&role=my_custom_role
YOu can use use hook_user_insert and check for the url and assign desired role,
function module_name_user_insert(&$edit, $account, $category)
{
if($_SERVER['REQUEST_URI'] =="url")
{
//add code to assign desired role;
//assuming rid of custom role is 1
$account->roles[1]='custom_role';
}
}
I encourage you to take a look at the rules module: https://www.drupal.org/project/rules/
This module allows you to create automated tasks based on events. What you want to do is:
Download and enable rules module: https://www.drupal.org/project/rules/
You'll need to enable rules UI as well
Go to rules configuration: example.com/admin/config/workflow/rules
Create a new rule
The rule event should be something like: "User registers a new account connected to Facebook"
The rule action should be something like: "Assign role to user"
Interface should be pretty straight forward.
Here's some additional resources:
Rules Handbook
https://www.drupal.org/documentation/modules/rules

FOSUserBundle ProfileFormType -> create different form

i'm on a Symfony project ( v2.5 ) and i'm using FOSUserBundle & OAuth for the login/sign in.
My problem is : I have different type of user with some that has more informations to edit in /profile/edit. That's why i'm trying in a simple way to get user informations to do a condition in the form builder. With one attribute i'm able to know which type of user i have and which form he needs.
After a lot of research i found this https://github.com/PUGX/PUGXMultiUserBundle/blob/master/Resources/doc/index.md
but that doesn't seem to be the best for my little problem.
Best regards,
Thanks for replying
I've found a way ( nasty but working )
Before creating the form, i've access to user, so I set the attribute in the Session, catching the attribute in the builder then unsetting the session

Drupal 7, user_profile_form form values not passing through drupal_get_form

Drupal 7, I want to load the user profile form into a module page. I have a custom field also that the user can configure, let's call this field "blah". It's a implemented as a dropdown field.
When I load the form using the following code everything is fine apart from the blah field which does not populate its user stored data.
form_load_include($form_state, 'inc', 'user', 'user.pages');
global $user;
$output .= drupal_render((drupal_get_form('user_profile_form', $user)));
Does anyone know how I would get the blah variable/value/user data into this rendered form? It is populated if I go to the standard user profile editing page at http://example.com/user/2/edit.
You should be able to achieve this using user_load api.
global $user;
$user_fields = user_load($user->uid);
print_r($user_fields);
Solved it! I think the very act of posting on Stack Overflow sometimes brings you around to working it out. It was just as simple as $user->field_blah['und'][0]['value'] = 12345;
Possible Solutions:-
1)If its a custom field make it belong to user entity bundle and true for user register form while attaching it to user bunble.
2)U can use field_attach_form,
3)form alter