Adding new fields to Admin User Info in magento - magento-1.7

By default when you try to add a new User in magento, it accepts only the following fields:
Username, FirstName, LastName, Email, New Password and Password Confirmation.
I want to add some more field here, e.g. About Me, PhoneNumber, etc where we will add additional information about this role specific users we add to magento.
Has anyone already done this? How should I go about doing this?
I know additional fields will need to be created in the database. The adminhtml userinfo.phtml doesn't mention fields like Username, FirstName etc, so where it is picking it up from?
Please advice.
Thanks,
Neet

You can start with following tutorial to create registration field
http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields

a) Adding new fields to Admin User Info in magento
b) Adding new fields to Admin User Info in Magento
You will need to add a column to the admin_user table. Make a table with the following code:
<?php
$installer->getConnection()->addColumn($installer->getTable('admin/user'),
'location', array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'length' => 256,
'nullable' => true,
'default' => null
));
?>
Then, if you want to add/edit this field from the backend you need to
rewrite the method Mage_Adminhtml_Block_System_Account_Edit_Form::_prepareForm and add a new
element in there:
<?php
$fieldset->addField('location', 'select', array(
'name' => 'location',
'label' => Mage::helper('adminhtml')->__('Location'),
'id' => 'location',
'title' => Mage::helper('adminhtml')->__('Location'),
'class' => 'input-select',
'style' => 'width: 80px',
'options' => array('1' =>
Mage::helper('adminhtml')->__('Russia'), '0' =>
Mage::helper('adminhtml')->__('India')),
));
?>
Clear the cache and run the code. You can add new fields to Admin User Info in Magento.

Related

After adding new column "name" to user table in yii2 advanced, data not getting saved in it

After assigning all required values to user model (column which i have added also). When I am using $model->save() data for all default attributes getting saved except the one I have added. I trying insert via REST call. If there is any other way to do please let me know. I have also followed this link https://github.com/dektrium/yii2-user/blob/master/docs/adding-new-field-to-user-model.md which is of no use.
this is my rules method in users model
public function rules()
{
return [
[['username', 'email'], 'filter', 'filter' => 'trim'],
[['username', 'email', 'status','name'], 'required'],
['email', 'email'],
['username', 'string', 'min' => 2, 'max' => 255],
// password field is required on 'create' scenario
['password', 'required', 'on' => 'create'],
// use passwordStrengthRule() method to determine password strength
$this->passwordStrengthRule(),
['username', 'unique', 'message' => 'This username has already been taken.'],
['email', 'unique', 'message' => 'This email address has already been taken.'],
];
}
Thank you.
User model which I was using extended from UserIdentity So I have added rules method in UserIdentity class but after adding new column to users table, that column should be specified in rules method of users model only which ever it might be extending. Previously there was no need of adding like this till Yii v2.1.0 may be in Yii 2.2.0 it has to be.

Drupal 7: Show fields on a form based on another field and a database lookup

I have a form I created in a custom module using the Form API. It is a fairly basic form with only 4 fields. It basically signs a user up for a job alert system. We are basing it only by email address with a few search parameters. We want people to be able to setup a search agent quickly and anonymously meaning they will NOT be creating a Drupal user account as we don't want them to have to deal with a password etc. They will just put in their email address, check off a few preferences and we will save the data.
Now the issue I need to deal with is allowing the user to edit their preferences later on and/or unsubscribe. Again this is not high security and it doesn't need to be. What I would like to do is initially ask ONLY for their email address in the form and allow them to submit it. I would then check the database to see if we already have an entry for that email address and if so, display the pre-filled form for them to edit or unsubsribe, other wise just show them the blank form. So I am just trying to figure out the best way to go about this. I'm thinking I just have one form with all of the fields including email address, but somehow only display the other fields besides the email address after a successful call to the database. I'm just tripping up on how to accomplish this.
EDIT:
I'm wondering if I can use Drupal's AJAX functionality to accomplish this? I tried this, but I couldn't get it to work. I put an Ajax attribute on my submit button with a wrapper ID and a callback function. I created a form element in my form with blank markup and used a prefix and suffix that created a wrapper div with the ID I used in my AJAX parameter. Then I am thinking in my callback function I can do the database lookup and then return the form elements I need either pre-filled or not into the wrapper div that was created, but when I do this, the form does submit via AJAX and I get the spinning wheel, but no matter what I return in my callback, it does not appear in my output wrapper div. Am I going about this the right way? I also made sure I have $form_state['rebuild'] = TRUE; on my original form.
Here is what I tried and it didn't work.
/**
* Implements hook_form().
*/
function _vista_form($form, &$form_state) {
$form = array();
$form_state['rebuild'] = TRUE;
$form['email'] = array(
'#type' => 'textfield',
'#title' => 'Email',
'#required' => TRUE,
);
$form['render_area'] = array(
'#type' => 'markup',
'#markup' => '',
'#prefix' => '<div id="job-agent-form">',
'#suffix' => '</div>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#attributes' => array('class' => array('submit')),
'#ajax' => array(
'callback' => '_display_form',
'wrapper' => 'job-agent-form',
'method' => 'replace',
'effect' => 'fade',
),
return $form;
}
function _display_form($form, &$form_state) {
// there are other form elements that would go here also, I just added two for example
$type_options = array(
'VISTA-HealthCare-Partners-Government' => 'Vista Healthcare Partners',
'International' => 'International Locum Tenens',
'Permanent' => 'Permanent Physician',
'US-Locum-Tenens' => 'US Locum Tenens',
);
$form['job_type'] = array(
'#type' => 'checkboxes',
'#multiple' => TRUE,
'#title' => 'Type of Job',
'#options' => $type_options,
'#empty_option' => 'Choose a placement type',
'#empty_value' => 'all',
//'#default_value' => $type_selected,
);
$form['active'] = array(
'#type' => 'checkbox',
'#title' => 'Subscribe/Unsubscribe',
'#default_value' => 1,
);
return $form;
}
I would go for creating all fields in the form than use hook_form_alter() to hide the unneeded ones with ['#access'] = FALSE.

Magento Custom Module - WYSIWYG image browse issue

I have a custom module with a content field (WYSIWYG editor)
When I select the insert image button, the following popup appears. For some reason the 'browse' button at the side of the Image URL has disappeared. Can someone point me in the right direction to get the image icon back? (what block/controller etc)
What is required when adding the full featured WYSIWYG editor to a custom magento module?
This is my form field element within Form.php (block)
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
));
Thank you.
Jonny
Had to find out the hard way, but the solution is quite simple:
Please check the permissions of your Role your Admin is in unser System=>Permissions=>Roles
There you can find in the Tab "Role Resources" the Checkbox "Media Gallery". Make sure this checkbox is ticked!
Then, clean cache, log out and in again and it should work.
Cheers!
I managed to sort this by adding some configuration options to the field,
Add the following code above the addField() of your WYSIWYG,
$configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array( 'add_widgets' => false, 'add_variables' => false, 'add_images' => false, 'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/'));
Once you've added the code, you need to add another param to the addField called 'config' calling your $configSettings variable.
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
'config' => $configSettings
));

Adding custom validation in zend framework

I have a mysql table named users having fields: username, password, email
I have controller/action like this 'user/update' for adding new user and 'user/update/id/{user_id}'
I have same Zend_Form for both controller. For adding new user, I've checked whether the username already exist or not using below code:
$username->addValidator('Db_NoRecordExists', true, array('table' => 'user', 'field' => 'username'));
This works well when new user is added but when editing the user, even when the user leaves the username field as it is, i get username already exist error.
Is their a validation that zend provide similar to Db_NoRecordExists for editing the field.
In editing case,i want query like:
SELECT COUNT(*) FROM users WHERE username='$username' AND id!=$update_id
How can i do this?
You can convert your sql query into Zend_Db_Select
$select = Zend_Db_Table::getDefaultAdapter()->select()->from('users')->where('username =?',$username)
->where('id != ?',$update_id);
$validator = new Zend_Validate_Db_NoRecordExists($select);
Zend_Validate_Db_NoRecordExists has an exclude option for this case:
$validator = new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'users',
'field' => 'username',
'exclude' => array(
'field' => 'id',
'value' => $user_id
)
)
);

Drupal: set id attribute in multi-step form

I'm building a multi-step form in Drupal 6. For some reason, the id attribute of the form element have an extra "-1" the first time the step 1 form is displayed.
For example, if the form name is "user-registration", the first time I access the step 1 form, the id is "user-registration-1". Then, if I go to step 2, the id is "user-registration". If I go back to step 1, the id remains "user-registration".
I'd like to know if there's a way for me to set the id attribute or to prevent Drupal from adding the extra "-1".
Thanks.
You can set the id yourself.
$form['#attributes'] = array('id' => 'user-registration');
Drupal 6.x has a form API property for both '#id' an '#attribute'. I had the same problem and found that the '#id' property was blank, which accounted for the blank 'id' in the form field. Then I used '#attribute' => array('id' => 'name of id'), which gave me a second 'id' in the form field. Remove the id in the '#attribute' and add another form API property for '#id'.
$form['foo'] = array(
'#type' => 'textfield',
'#title' => t('Foo'),
'#required' => FALSE,
'#id' => 'text-foo',
);
This worked for me:
$form = array( '#id' => 'myformid' );