I am new to drupal.
I need to customize a registration form by adding fields like id,mobile etc.
Can I accomplish this by creating a custom module?
If yes could anyone please help me with a brief idea on creating and overriding the default user registration submit function. I have to insert these details to another table and also have to pass the data as a service request.
Ive created a custom module with function
module_form_alter(&$form,&$form_state,$form_id){
$form['#submit'] = 'module_form_submit';
if($form_id == 'user_register_form'){
//print_r($form_id);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('id'),
'#default_value' => '',
'#size' => 60,
'#maxlength' => 15,
'#required' => TRUE,
);
}
}
function module_form_submit($form, &$form_state){
echo "test";
exit();
}
module_form_alter is being called and I can see the new field on the registration screen but the submit function is still not called. I need to override the default drupal register submit.
I already have the following function in my theme template.php
function templatename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'portal_preprocess_user_login'
),
);
$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'portal_preprocess_user_register_form'
),
);
$items['user_pass'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-pass',
'preprocess functions' => array(
'portal_preprocess_user_pass'
),
);
return $items;
}
user-register-form.tpl.php
<div class="form-group">
<?php print drupal_render_children($form); ?>
</div>
And page--user--register.tpl.php with the html
<div id="login-page">
<div class="container">
<div class="form-login" >
<h2 class="form-login-heading"><img src="<?php echo drupal_get_path('theme', 'portal') . '/images/logo.png'; ?>" width="100"><?php echo $createaccount; ?></h2>
<div class="login-wrap">
<?php
$elements = drupal_get_form("user_register_form");
$form = drupal_render($elements);
echo $form ?>
<?php if ($messages):?>
<div id="messages-console" class="clearfix">
<div class="grid_12">
<div class="mt-grid-fix">
<?php print $messages; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
Is this approach fine or should I change this approach inorder to make my custom module functional?
You can go to:
admin/config/people/accounts/fields
and add the fields that you need.
In the fieldset "User settings" don't forget check "Display on user registration form."
Related
Basically i have 3 forms.
I have one action in my form and i want create 3 steps form using session.
I want when i click the next button it validates the form1,if successful then redirects to form2..
like wise for form3 but keep all the data in session and in third step the action goes runs and add all the data to database.
I only need to check conditions from session before my insert goes run in my action addjob.
Plz help me to do this.
My main question is how to get all the post data in one session variable and check step by step before insert..
i am learner in cakephp and i have not enough idea about session.
if you are a expert then plz do this.
public function addjob($id = NULL) {
$this->layout = "layout_registration_old";
$this->loadcategory();
$this->loadcargo();
//$this->loadsubcategory();
$this->getCountries();
$this->getstates();
if ($this->request->is('put') || $this->request->is('post')) {
if (isset($id)) {
$this->Job->id = $id;
} else {
$this->request->data['Job']['status'] = 1;
$this->request->data['Job']['job_type'] = 1; //this is used to update the job type private or public.
$this->Job->create();
}
$this->Job->set($this->request->data);
if ($this->Job->AddEdit()) { // ADDEdit is the validation name in model
if ($this->Job->save($this->request->data['Job'], false)) {
if (isset($id)) {
$this->Session->setFlash(__('Job has been updated sucessfully.'));
} else {
$this->Session->setFlash(__('Job has been added succesfully.'));
}
$this->redirect(array('controller' => 'jobs', 'action' => 'index'));
}
} else {
$errors = $this->Job->validationErrors;
$this->Session->setFlash(__('Please check your entry.'), 'flash_error');
}
}
if (isset($id)) {
$this->request->data = $this->Job->find('first', array('conditions' => array('id' => base64_decode($id))));
}
}
form - 1
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('customer_name',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('customer_no',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('customer_email',array('div' => false, 'label' => false));?>
<?php
echo $this->Form->input('transport_type', array(
'type' => 'select',
'label' => false,
'class' => 'select',
'options' => array(
1 => 'Road'
),
));
?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
form - 2
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('fname',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('lname',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('email',array('div' => false, 'label' => false));?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
form - 3
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('shop',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('business',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('status',array('div' => false, 'label' => false));?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
Instead of saving the data from first 2 forms in a session, you should implement a multi part form using any javascript solution (Form wizard). Validate the data of each step using javascript or via ajax (if needs to be done dynamically) before moving to the next step and submit form at the end so that you don't have to play with sessions.
Example link
PS - This could go as a comment to the question but I haven't gained enough reputations to post comments yet :(
I have 3 dependent dropdowns, and a textfield being dependent to the last dropdown. If one of the value in the last dropdown, I want the textfield value dynamically changes based on the selected value (it's from the same Database table).
This is the view of the third dropdown:
<div class="row" id="id_subkeg">
<?php echo $form->labelEx($model, 'id_subkeg'); ?>
<?php
echo $form->dropDownList($model, 'id_subkeg', array(), array(
'style' => 'width: 100%',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('dynamicSatuan'),
'update' => '#' . CHtml::activeId($model, 'satuan'),
//'update'=>'#seksi',
'data' => array('id_subkeg' => 'js:this.value'),
)
)
);
?>
<?php echo $form->error($model, 'id_subkeg'); ?>
</div>
This is the textfield view:
<div class="row" id="satuan">
<?php echo $form->labelEx($model, 'satuan'); ?>
<p class="hint" style="font-size: 80%">Contoh: Dokumen.</p>
<?php echo $form->textField($model, 'satuan', array('style' => 'width: 98%;', 'readonly' => FALSE)); ?>
<?php echo $form->error($model, 'satuan'); ?>
</div>
And this is the action in the controller:
public function actionDynamicSatuan() {
//$data = Subkegiatan::model()->findByPk($_POST['id_subkeg']);
$data = Subkegiatan::model()->findByPk('id_subkeg=:id_subkeg', array(':id_subkeg' => (int) $_POST['id_subkeg']));
echo $data->satuan;
}
But it's not been working for days. I don't know which part I've missed. My guess is that the dropdown is a dependent dropdown to the one above it. So I must have missed at some part.
Any help is highly appreciated.
UPDATE:
After days of searching, finally got it:
public function actionDynamicSatuan() {
$param_country = (int) $_POST['id_subkeg'];
$maxOrderNumber = Yii::app()->db->createCommand()
->select('satuan')
->from('subkegiatan')
->where('id_subkeg = ' . $param_country)
->queryScalar();
echo '<b>SATUAN: '. $maxOrderNumber.'</b>';
//echo CHtml::tag('input', array('type' => 'text', 'value' => $maxOrderNumber));
}
Instead of update, use success callback:
echo $form->dropDownList($model, 'id_subkeg', array(), array(
'style' => 'width: 100%',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('dynamicSatuan'),
'data' => array('id_subkeg' => 'js:this.value'),
'success'=> 'function(data) {
$("#your_id_here").empty();
$("#your_id_here").append(data);
}'
)
)
);
<div class='rate-results'>
<div class='button-container'>
<input type='submit' id='btn-calculate' class='pure-button pure-button-primary' value='{$a['label_button_continue']}'></input>
</div><div class='rate-container'>
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
<div id='calculated_rate'>{$a['default_price']}</div>
</div>
how can i apply a link to this button?
['label_calculated_rate']
seems to pull the text
"GET A QUOTE"
from code up above it, but nowhere can i find how to turn this button into a link. The mentioned above code is as follows...
static function handle_shortcode($atts){
self::$add_script = true;
self::$add_styles = true;
$a = shortcode_atts( array(
'title' => 'Get a FREE Price Estimate',
'label_days' => 'Total days of coverage needed?',
'units_days' => 'days',
'label_attendance' => 'Estimated daily attendance?',
'units_attendance' => 'people',
'label_event_type' => 'What type of event is it?',
'label_sample_certificate' => 'View sample certificate',
'link_sample_certificate' => '#',
'label_button_continue' => 'Get Free Quote',
'label_calculated_rate' => 'Estimated Cost',
'default_price' => '$ 95.95',
'form_action' => 'javascript:void(0);',
'default_event_type' => ""
), $atts);
return "<form action='{$a['form_action']}' id='main_calculator' class='pure-form pure-form-aligned' data-default-event-type='{$a['default_event_type']}'>
<h3 class='title'>{$a['title']}</h3>
Replace
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
with
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
Replace http://www.w3schools.com/html/ with where you want the button to link to.
Hence adding a link to the button:
['label_calculated_rate']
I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list
I want to pass a php variable to modal window , what i am doing is opening a modal window using this link , but i want to pass a variable to this link and get same variable in modal window , i try to to do this to append a text in some div but it return html that i am unable to get in query
echo CHtml::link(
'Set Recipe', '', array(
'class' => 'testclass',
'id' => $finalDate,
'data-toggle' => 'modal',
'data-target' => '#myModal',
'fahadVar' => $finalDate
));
and when i click this button i got modal window how to get variable set in button
Here is simple modal code of yiibooster
<div class="modal-body">
<p>One fine body...</p>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'label' => 'Save changes',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Close',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
thanks in advance
You should create a Widget.
Note: I copied below from another post. It works like charm.
First Create a new widget. Let say the name is CategoryWidget. Put this widget under components directory protected/components.
class CategoryWidget extends CWidget {
public function run() {
$models = Category::model()->findAll();
$this->render('category', array(
'models'=>$models
));
}
}
Then create a view for this widget. The file name is category.php. Put it under protected/components/views
category.php
<?php if($models != null): ?>
<ul>
<?php foreach($models as $model): ?>
<li><?php echo $model->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then call this widget from your main layout.
main.php
// your code ...
<?php $this->widget('CategoryWidget') ?>