I'm not a drupal/web programmer but have a site on drupal and after I reloaded server, user registration standard form has some failures.
It changed names of the fields while they work fine.
Instead of "Login" label now I have "Search" label but again users can still login. But this label makes me crazy and it is quite hard to understand where I can find this problem to fix it.
How I can change this label to be correct?
Paste this code to your theme/template.php and rename my_theme_form_alter to your theme name
function my_theme_form_alter(&$form, &$form_state, $form_id){
switch($form_id){
case 'user_register_form':
unset($form['account']['mail']['#title']);
$form['account']['mail']['#description'] = '';
$form['account']['mail']['#attributes']['placeholder'] = t('E-mail');
$form['account']['#attributes']['class'][] = 'form-elements';
$form['account']['pass']['#description'] = '';
$form['account']['pass']['#process'] = array('form_process_password_confirm', 'register_alter_password_confirm');
$form['actions']['submit']['#value'] = t('Register');
break;
}
}
function register_alter_password_confirm($element) {
$element['pass1']['#title_display'] = "invisible";
$element['pass1']['#attributes']['placeholder'] = t("Password");
$element['pass2']['#title_display'] = "invisible";
$element['pass2']['#attributes']['placeholder'] = t("Confirm password");
return $element;
}
Related
Anyone had any luck with this?
I'm using 9.04.01 on DNN 9.
There doesn't appear to be a way to add a question unlike it's previous version.
The previous version had a + sign in the menu on the right to add a new question. This version doesn't. Is there a different way to add questions in this version?
Images http://robertveale.com/
Thanks.
You actually ran into something different. Please check http://2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content to understand this
Your first view shows a list of content-assigned-to-the-module so you have the inline +.
The second view shows a list querying the DB, so hitting + wouldn't add it below that but anywhere else, so it's not part of the item-toolbar. If you need a + on the query-view, then the most common solution is to provide a separate + button - see for example how the blog-app does it here: https://github.com/2sic/app-blog/blob/master/_1%20Main%20blog%20view.cshtml#L24-L38
#* toolbar for add / manage posts *#
#Edit.Toolbar(toolbar: new object[] {
new {
command = new {
action = "new",
contentType = "BlogPost"
}
},
new {
command = new {
action = "contentitems",
contentType = "BlogPost"
},
showCondition = true
}
}, settings: new { hover="left", show = "hover" })
My need is to change behavior of edit form, for several content types.
The objective is:
-After update button has been pressed, don't update the node but create a new one with values from old node. I could do that by passing old node's fields values to "/node/add/my_content" form but this require a lot of work (the forms are quite complicated) and on edit page i have already all values ready in my fields.
So i already tried hook_form_alter
function mymodule_form_alter (&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'my_not_update_form':
$node = $form_state['node'];
if (!isset($node->nid) || isset($node->is_new)) {
// This is a new node.
}
else {
$new_node = new StdClass();
$new_node->type = 'my_not_update_form';
node_object_prepare($new_node);
$new_node->uid = $user->uid;
$new_node->language = 'und';
$new_node->title = NULL;
$form['vid']['#value'] = NULL;
$form['nid']['#value'] = NULL;
$form['created']['#value'] = $new_node->created;
$form['changed']['#default_value'] = NULL;
$form['#node'] = $new_node;
$form['#entity'] = $new_node;
$form_state['node'] = $new_node;
$form_state['build_info']['args'][0] = $new_node;
}
break;
}
}
So with the above code i'm able to create a new node but the "create date" parameter always stay the same as create date parameter of an old node and none of the above line can solve that problem.
If you want to create an entirely new node when you submit edits to an existing node, then you want to use hook_node_presave(), which allows you to set any property of the node object before it's saved to the database.
In this example unsetting the nid and vid, and explicitly setting the is_new property will achieve this:
function my_module_node_presave($node) {
unset($node->nid);
unset($node->vid);
$node->is_new = TRUE;
}
This will leave the existing node untouched and unedited, and will instead create an entirely new node.
So to fully change the behavior of form update i give up on hook_form_alter() and instead i used hook_node_presave
function mymodule_node_presave($node) {
if($node->is_new == FALSE || isset($node->nid)) {
unset($node->nid);
unset($node->vid);
unset($node->vuuid);
$node -> created = time();
$node -> timestamp = time();
$node-> is_new = TRUE;
$node -> changed = time();
unset($node->revision_timestamp);
unset($node->num_revisions);
unset($node->current_revision_id);
unset($node->is_current);
unset($node->is_pending);
unset($node->revision_moderation);
unset($node->date);
unset($node->vuuid);
unset($node->data);
}
}
I'm building a registration component on a Sitecore Site (Sitecore 7.0 ) and while the users are being created, none of the custom profile or role is being created. There are no errors in the logs. The user that is created has the correct user name and domain, but does not have the custom profile and lacks the full name, email address, role and additional custom fields. Has anyone encountered any related difficulties achieving this?
N.b. using email address as username if that will make any difference. I've updated the config to allow this. I've also added some logging underneath, which all outputs the correct information.
Here's a sample of the code:
try
{
if (!User.Exists(userEntity.EmailAddress))
{
var user = Membership.CreateUser(CreateUserName(userEntity), userEntity.Password,
userEntity.EmailAddress);
User scUser = User.FromName(userEntity.EmailAddress, true);
if (Role.Exists(Constants.Roles.ExampleRole) && !scUser.IsInRole(Constants.Roles.ExampleRole))
{
Roles.AddUserToRole(userEntity.EmailAddress, Constants.Roles.ExampleRole);
}
if (scUser != null)
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
scUser.Profile.FullName = userEntity.FirstName + " " + userEntity.LastName;
scUser.Profile.ProfileItemId = Constants.CustomUserProfile.ToString();
scUser.Profile.SetCustomProperty(UserFields.FirstName, userEntity.FirstName);
scUser.Profile.SetCustomProperty(UserFields.LastName, userEntity.LastName);
scUser.Profile.SetCustomProperty(UserFields.EmailAddress, userEntity.EmailAddress);
scUser.Profile.SetCustomProperty(UserFields.TelephoneNumber, userEntity.TelephoneNumber);
scUser.Profile.SetCustomProperty(UserFields.CompanyName, userEntity.CompanyName);
scUser.Profile.SetCustomProperty(UserFields.Sector, userEntity.Sector);
scUser.Profile.SetCustomProperty(UserFields.AddressLine1, userEntity.AddressLine1);
scUser.Profile.SetCustomProperty(UserFields.AddressLine2, userEntity.AddressLine2);
scUser.Profile.SetCustomProperty(UserFields.City, userEntity.City);
scUser.Profile.SetCustomProperty(UserFields.PostCode, userEntity.Postcode);
scUser.Profile.SetCustomProperty(UserFields.State, userEntity.State);
scUser.Profile.SetCustomProperty(UserFields.Country, CountryUtility.GetCountryNameById(userEntity.SelectedCountryId));
scUser.Profile.Save();
result = true;
}
Membership.UpdateUser(user);
Log.Info(scUser.Profile.FullName, new object());
Log.Info(scUser.Profile.ProfileItemId, new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.FirstName), new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.City), new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.Country), new object());
Log.Info(scUser.IsInRole(Constants.Roles.ExampleRole) ? "true" : "false", new object());
}
}
else
{
throw new Exception(Nodes.Dictionary.Fields[DictionaryFields.RegistrationForm.UsernameExists].Value);
}
}
catch (Exception exception)
{
Log.Error(exception.Message, "RegistrationController");
}
I think you need to use the fully qualified user name when loading the user from Sitecore, like this (assuming extranet domain):
User scUser = User.FromName("extranet\\" + userEntity.EmailAddress, true);
The reason everything seems to work in your code is because you get a user back from User.FromName(...) wether the user actually exists or not.
I want to change email addresses based on postal codes entered by users.
My code looks something like below:
function my_webform_tracker_webform_submission_render_alter(&$renderable) {
$node_id = (int)$renderable['#node']->nid;
if ($node_id == 257) {
$postal_code = (int)$renderable['#submission']->data[5][0];
if($postal_code >= 14000 && $postal_code <= 14990) {
$renderable['#email'][email] = "thisemailid#mydomain.com";
$renderable['#node']->webform['emails'][1]['email'] = "thisemailid#mydomain.com";
$renderable['#node']->webform['emails'][2]['email'] = "thisemailid#mydomain.com";
//print "<pre>"; print_r($renderable); exit;
}
}
}
I tried a lot but the email id seems to be not changed.
Please help me figure this out.
Are you trying to dinamycally change the email after the user enter a postal code on the screen?
If so you need to make an ajax call on the field postal code (detect a change) to reload the field email of your webform.
Also I will go with a hook_form_alter on the webform (hook_form_"webform id"_alter()) rather than the hook you are using
I figured it out, actually I was using wrong hook to do the task. The right one should be "hook_webform_submission_presave". So my code will look like,
function my_webform_tracker_webform_submission_presave($node, &$submission) {
$postal_code = (int)$renderable['#submission']->data[5][0];
if($postal_code >= 14000 && $postal_code <= 14990) {
$node->webform['emails'][1]['email'] = "thisemailid#mydomain.com";
$node->webform['emails'][2]['email'] = "thisemailid#mydomain.com";
}
}
Thank You everyone for help!!
I have a very simple form created with Gravity Forms;
It submits two numbers and then redirects to a different result page.
How do I retrieve those two numbers on the result page?
add_filter("gform_confirmation_4", "custom_confirmation", 3, 4 );
function custom_confirmation($confirmation, $form, $lead, $ajax)
Gives a custom confirmation. Each field value can be retrieved by using $lead[{field ID}]
I have a solution for this based on using a combination of form submission hooks and the GForms API. It's a horrible plugin so I apologise for the messiness of the logic flow. It's important to use the framework methods rather than processing the data yourself since there are a good amount of hacks and shonky things going on in there to correctly match field IDs and so forth.
I will provide a solution to pass a submission from one form to pre-populate another. Changing the destination for POST data is pretty straightforward, they have an example for it on their gform_form_tag hook documentation page. Yes, that really is the only way of doing it.
Without further ado here is the code. I've set it up to work off form configuration to make things simpler for the end user, so it works like this:
Select "allow field to be populated dynamically" in your destination form field's advanced settings and choose a parameter name for each.
Add matching CSS classes on the source fields of the other form(s) to setup the associations.
Add a CSS class to the source forms themselves so that we can quickly check if the redirection is necessary.
.
$class = 'GForms_Redirector';
add_filter('gform_pre_submission', array($class, 'checkForSubmissionRedirection'), 10, 1);
add_filter('gform_confirmation', array($class, 'performSubmissionRedirection'), 10, 4);
abstract class GForms_Redirector
{
const SOURCE_FORMS_CLASS_MATCH = 'submission-redirect';
const DEST_PAGE_SLUG = 'submit-page-slug';
const DEST_FORM_ID = 1;
protected static $submissionRedirectUrl;
// first, read sent data and generate redirection URL
function checkForSubmissionRedirection($form)
{
if (false !== preg_match('#\W' . self::SOURCE_FORMS_CLASS_MATCH . '\W#', $form['cssClass'])) {
// load page for base redirect URL
$destPage = get_page_by_path(self::DEST_PAGE_SLUG);
// load form for reading destination form config
$destForm = RGFormsModel::get_form_meta(self::DEST_FORM_ID, true);
$destForm = RGFormsModel::add_default_properties($destForm);
// generate submission data for this form (there seem to be no hooks before gform_confirmation that allow access to this. DUMB.)
$formData = GFFormsModel::create_lead($form);
// create a querystring for the new form based on mapping dynamic population parameters to CSS class names in source form
$queryVars = array();
foreach ($destForm['fields'] as $destField) {
if (empty($destField['inputName'])) {
continue;
}
foreach ($form['fields'] as $field) {
if (preg_match('#(\s|^)' . preg_quote($destField['inputName'], '#') . '(\s|$)#', $field['cssClass'])) {
$queryVars[$destField['inputName']] = $formData[$field['id']];
break;
}
}
}
// set the redirect URL to be used later
self::$submissionRedirectUrl = get_permalink($destPage) . "?" . http_build_query($queryVars);
}
}
// when we get to the confirmation step we set the redirect URL to forward on to
function performSubmissionRedirection($confirmation, $form, $entry, $is_ajax = false)
{
if (self::$submissionRedirectUrl) {
return array('redirect' => self::$submissionRedirectUrl);
}
return $confirmation;
}
}
If you wanted to pass the form values someplace else via the querystring then you'd merely need to cut out my code from the callback and build your own URL to redirect to.
This is a very old question, now you can send it using a Query String on the confirmation settings.
They have the documentation on this link:
How to send data from a form using confirmations
Just follow the first step and it will be clear to you.