Magento - Extra Address Fields (during registration) - forms

At customer registration:
By default, Magento uses the supplied customer name to auto-populate the default shipping / billing information. We are a B2B, and need to gather that information separately at the time of registration. Additionally, we need to get the address fax number.
These are not custom attributes (already made a bunch of those, and have integrated them into a greatly expanded registration form), but the standard first name, last name and fax fields associated with a customer address.
I've attempted this:
<span class="msg">Default shipping and billing information.</span>
<ul class="form-list">
<li class="fields">
<div class="field billing_name">
<label for="billing_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?></label>
<div class="input-box">
<input type="text" name="billing_firstname" id="billing_firstname" value="<?php echo $this->htmlEscape($this->getFormData()->getFirstName()) ?>" title="<?php echo $this->__('First Name') ?>" class="input-text required-entry" />
</div>
</div>
<div class="field billing_name">
<label for="billing_lastname" class=""><em>*</em><?php echo $this->__('Last Name') ?></label>
<div class="input-box">
<input type="text" name="billing_lastname" id="billing_lastname" value="<?php echo $this->htmlEscape($this->getFormData()->getLastName()) ?>" title="<?php echo $this->__('Last Name') ?>" class="input-text required-entry" />
</div>
</div>
</li>
but I'm not clear what the input name should be. Whatever the case, the account names are used instead.
Looking for a little information on maybe the "name" of the form fields required, and some method of disabling the auto-populate feature, should that also be required.
cheers
Update
Looking at this a little more closely.
I'm overriding the mage/customer/controller/accountController.php :: createPostAction() and I see in the controller the location where the form is processed and populated as a customer entity.
I'm trying something like this
if ($this->getRequest()->getPost('create_address')) {
/* #var $address Mage_Customer_Model_Address */
$address = Mage::getModel('customer/address');
/* #var $addressForm Mage_Customer_Model_Form */
$addressForm = Mage::getModel('customer/form');
$addressForm->setFormCode('customer_register_address')
->setEntity($address);
$addressData = $addressForm->extractData($this->getRequest(), 'address', false);
$addressErrors = $addressForm->validateData($addressData);
if ($addressErrors === true) {
$address->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
$addressForm->compactData($addressData);
// attempting to jam vars into address obj
$address['_data']['firstname'] = $this->getRequest()->getPost('billing_firstname');
$address['_data']['lastname'] = $this->getRequest()->getPost('billing_lastname');
$address-['_data']['fax'] = $this->getRequest()->getPost('billing_fax');
// end
Mage::log('createPostAction, after var jam: '. print_r($address, true ) );
$customer->addAddress($address);
$addressErrors = $address->validate();
if (is_array($addressErrors)) {
$errors = array_merge($errors, $addressErrors);
}
} else {
$errors = array_merge($errors, $addressErrors);
}
}
When i log this out:
2012-12-18T01:51:10+00:00 DEBUG (7): createPostAction, after var jam: Mage_Customer_Model_Address Object
(
[_customer:protected] =>
[_eventPrefix:protected] => customer_address
[_eventObject:protected] => customer_address
[_resourceName:protected] => customer/address
[_resource:protected] =>
[_resourceCollectionName:protected] => customer/address_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_type_id] => 2
[entity_id] =>
[is_default_billing] => 1
[is_default_shipping] => 1
[firstname] => Chirp // customer firstname
[lastname] => Anaplex // customer lastname
[company] => some agency
[street] => 2345 somewhere dr
[city] => somecity
[country_id] => US
[region] =>
[region_id] => 44
[postcode] => 84151
[telephone] => 123-123-1233
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] => entity_id
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
The form variables are getting passed successfully ( i see them in the log ), but I seem to be unable to insert them into the address object this way. I get the following Notice:
2012-12-18T16:39:39+00:00 ERR (3): Notice: Indirect modification of overloaded element of Mage_Customer_Model_Address has no effect in /root/namespace/module/controllers/AccountController.php on line 79
If this is "Indirect" - what is the "Direct" method?
Anyone?

Derp. This works.
$address->setData('firstname', $this->getRequest()->getPost('billing_firstname'));
$address->setData('lastname', $this->getRequest()->getPost('billing_lastname'));
$address->setData('fax', $this->getRequest()->getPost('billing_fax'));
Anyone else needing this?
Add form fields into your/theme/template/persistent/forms/register.phtml
override Mage_Customer_AccountController
setData('key', 'value') in yourmodule/customer/controller/accountController.php :: createPostAction()

Related

How to post multiple inputs in database

I'm working with Codeigniter, on a sales targets' form for salesmen.
They have to input values for each product, locality, year, etc.
Product and locality are already get with existing database: no need to set rules (see controller).
When I checked the post (with enable_profiler of Codeigniter), I get this:
The problem is these datas don't insert into the database table.
I read and tested a lot, but always blocked.
Here is my model:
public function add($params)
{
$this->db->insert($this->table, $params);
return $this->db->insert_id();
}
My controller:
$this->load->library('form_validation');
$this->form_validation->set_rules('year', 'Year', 'required|integer');
$this->form_validation->set_rules('prevision', 'Prevision', 'required');
$this->form_validation->set_rules('value', 'Value', 'required|integer');
if ($this->form_validation->run()) {
$params = array(
'year' => $this->input->post('year'),
'prevision' => $this->input->post('prevision'),
'locality_id' => $this->input->post('locality'),
'product' => $this->input->post('product'),
'value' => $this->input->post('value'),
);
$this->Objectif_model->add($params);
redirect('admin/objectif');
} else {
$this->layout('admin/objectif/add');
}
And my view with inputs:
<?php foreach ($products as $product) : ?>
<tr class="form-group">
<td class="bg-warning">
<?= $product->grp_product; ?>
</td>
<td class="bg-warning product">
<?= $product->code; ?>
</td>
<?php foreach ($localities as $locality ) : ?>
<td>
<input type="text" class="form-control valeur" placeholder="Value k€" name="value[]" data-validation="number" data-validation-ignore="./" data-validation-optional="true" />
<input type="text" name="year[]" />
<input type="text" name="prevision[]" />
<input type="text" name="product[]" value="<?= $product->code ?>" />
<input type="text" name="localite_id[]" value="<?= $locality->id ?>" />
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
Hope you will help me.
I find my answer.
In my controller, I had to pass each post in a variable and made a loop.
//action post in a var for each data
$id = $this->input->post('id');
$prev = $this->input->post('prevision');
$year= $this->input->post('year');
$locality_id = $this->input->post('locality_id');
$product = $this->input->post('product');
$value= $this->input->post('value');
if ($this->form_validation->run()) {
$count_id = count($id);
if (isset($id)) {
for ($i = 0; $i < $count_id; $i++) {
$obj[$i] = array(
'id' => $id[$i],
'prevision' => $prev,
'year' => $year,
'locality_id' => $locality_id[$i],
'product' => $product[$i],
'value' => $value[$i]*1000
);
} // endfor
if (isset($obj)) {
$this->Objectif_model->add_obj($obj);
} // endif
}// endif isset
}// endif form validation

Password input type="password" is displayed like "text" on screen?

I've installed a plugin and I'm happy with it- until it comes to the password field section of the registration form. For some inexplicable reason the password is displayed as text upon entry, forcing the user to first actively press the "hide password" button to hide it. So by default the field input is displayed as "text" on screen and not "password". However, here is the code...
function bp_nouveau_signup_form( $section = 'account_details' ) {
$fields = bp_nouveau_get_signup_fields( $section );
if ( ! $fields ) {
return;
}
foreach ( $fields as $name => $attributes ) {
if ( 'signup_password' === $name ) {
?>
<label for="pass1"><?php esc_html_e( 'Choose a Password (required)', 'buddypress' ); ?></label>
<div class="user-pass1-wrap">
<div class="wp-pwd">
<div class="password-input-wrapper">
<input type="password" data-reveal="1" name="signup_password" id="pass1" class="password-entry" size="24" value="" <?php bp_form_field_attributes( 'password', array( 'data-pw' => wp_generate_password( 12 ), 'aria-describedby' => 'pass-strength-result' ) ); ?> />
<button type="button" class="button wp-hide-pw">
<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
</button>
</div>
<div id="pass-strength-result" aria-live="polite"><?php esc_html_e( 'Strength indicator', 'buddypress' ); ?></div>
</div>
<div class="pw-weak">
<label>
<input type="checkbox" name="pw_weak" class="pw-checkbox" />
<?php esc_html_e( 'Confirm use of weak password', 'buddypress' ); ?>
</label>
</div>
</div>
... as you can see it is already set to <input type="password" .... So it doesn't make sense to an amateur like me.
The... <?php bp_form_field_attributes( 'password', array( 'data-pw' => wp_generate_password( 12 ), 'aria-describedby' => 'pass-strength-result' )... simply autogenerates and fills the field with an autogenerated password. When using this part it would of course make sense to display the autogenerated password as text first, but that wont be the case for me.
I'm trying to achieve a default setup, that hides the key inputs on screen by default upon password-entry, instead of the other way around like it is now.
All the help is appreciated!

daterangepicker and codeigniter form not working

I'm using an example of bootstrap-datetimepicker in my codeigniter project.
I create a form with only the datetimepicker input.
view:
<?php // Change the css classes to suit your needs
$attributes = array('class' => '', 'id' => '');
echo form_open('/calendario/nadevent/', $attributes); ?>
<div class="form-group">
<label for="reservationtime">Fecha:</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="text" name="reservationtime" id="reservationtime" class="form-control" value="<?php echo set_value('reservationtime') ?>" />
</div>
</div>
<?php echo form_submit( 'submit', 'Submit','class="btn btn-default"'); ?>
<?php echo form_close(); ?>
JS:
$('#reservationtime').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'DD-MM-YYYY hh:mm:ss', timePicker12Hour: false, separator: '/'});
The datepicker works fine but when i submit the form, I want to format the data and split into an array:
Controller:
$this->form_validation->set_rules('reservationtime', 'reservationtime', '');
$array = explode('/',set_value('reservationtime'));
Then I try to insert the values:
form_data = array(
'start' => $array[0],
'end' => $array[1]
;
But if I print the array, its empty:
Array ( [start] => [end] => )
Wha'ts wrong with the code?
Thanks for the help :)
You really not getting data from your form, can you dump the $_POST?

Yii radio buttons issue

i generate radio buttons using Yii
the code looks like
<span class="gender">
<?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'male')); ?>
</span>
<span class="gender">
<?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'female')); ?>
</span>
It's generate next HTML code
<span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">
<input value="male" class="male" name="web\models\register[gender]"id="web\models\register_gender" type="radio"></span>
<span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">
<input value="female" class="female" name="web\models\register[gender]" id="web\models\register_gender" type="radio">
</span>
when i get POST from this form, if i checked female it returns female, but if i cheked male it returns 0. I think it is because of identical inputs ids. But how can i avoid it?
You can configure activeRadioButton to not output the "guard input" with value 0. Do this by passing the parameter 'uncheckValue' => null as part of your options array:
echo CHtml::activeRadioButton($model,'gender',
array('value' => 'male', 'uncheckValue' => null));
echo CHtml::activeRadioButton($model,'gender',
array('value' => 'female', 'uncheckValue' => null));
That said, using activeRadioButtonList is the best choice here. You can configure its template parameter to specify your custom HTML:
$genders = array('male' => 'male', 'female' => 'female');
$options = array(
'template' => '<span class="gender">{input</span>',
'uncheckValue' => null,
);
echo CHtml::activeRadioButtonList($model, 'genger', $genders, $options);

select menu default values not rendering in symfony

I am using Symfony 1.4, and am using embedded forms to place multiple similar forms into one form for a configuration page. I am having success showing the form, but the default values of the sfWidgetFormChoice widgets are not being rendered, i.e. the selected="selected" attribute is gone from the HTML.
Incidentally, the default values show up if I don't use embedded forms. The problem with avoiding embedded forms is that each form has identical inputs and therefore overwrites itself.
The action code is as such, some code omitted for brevity:
$serviceFormArray = array();
$this->fullForm = new ConfigForm();
foreach($this->serviceArray as $net => $service)
{
$this->partialForm = new ConfigForm();
foreach($service as $typeId => $val)
{
$typeObj = Doctrine::getTable('Type')->find($typeId);
$typeField = new sfWidgetFormChoice(array(
'default' => $val,
'choices' => array('1' => 'on', '0' => 'off'),
'label' => $typeObj->name)
);
$typeField->setDefault($val);
$serviceFormArray[$typeObj->name] = $typeField;
}
$netObj = Doctrine::getTable('Network')->find($net);
$this->partialForm->setWidgets($serviceFormArray);
$this->fullForm->embedForm($netObj->name,$this->partialForm);
}
and the template looks like this, some code omitted for brevity:
<div class="sectionBox">
<?php echo $fullForm->renderFormTag('/configure/submitconfig') ?>
<?php foreach ($fullForm->getVisibleFields() as $part => $field): ?>
<div class="settingsField">
<?php echo $field->renderLabel() ?>
<?php echo $field->render() ?>
<input type="hidden" name="plug" value="<?php echo $plugName; ?>"/>
</div>
<?php endforeach; ?>
<div id="submitConfig"><input type="submit" value="Save"/></div>
</form>
</div>
Try setting default value via $form->setDefault($name, $default).
$this->partialForm->setDefault($typeObj->name, $val);