calling of javascript function on button click in .module file in drupal - drupal-6

I have one button and onclick i want javascript function to be called which contains alert message...............in drupal
i tried many things like...........
1)i created button using
$form['click'] = array(
'#type' => 'button',
'#attributes' => array('onclick' =>_____________),//dnt know what to give for onclick
'#value' => t('click'),
);
2)used drupal_add_js(drupal_get_path('module', 'document').'/eg.js', 'module');in hook_form_alter()
3).js file is as follows
function message()
{
alert("Catch ->This alert box was called");
} -->
want alert message to be displayed on button click.
Kindly help................
Thanks in advance

$form['search_something'] = array(
'#type' => 'button',
'#value' => t('Search'),
'#attributes' => array('onclick' => 'searchsomething()),
);
this is the piece of code to call javascript on button click.
Javascript function
function searchsomething(){
alert("hello");
}

Related

submit button can't find save method

I have a form that use submit button. My submit button always refer to mypages.com/pages/save, but my save function can appear with mypages.com/save. are there any ways to make my submit button refer to /save not /pages/save?
I put this in my route, but not work
$routes->get('/save', 'pages::save');
this is what happend when I try /pages/save
and this what happen when I try /save, its error cause it suppose open when I hit submit button
this is my save function
public function save()
{
$beli = $this->request->getvar('berasbeli');
$this->zakatModel->save(
[
'nama' => $this->request->getVar('nama'),
'alamat' => $this->request->getVar('alamat'),
'telp' => $this->request->getvar('telp'),
'jmlhjiwa' => $this->request->getVar('jmlhjiwa'),
'berasbeli' => $this->request->getVar('berasbeli'),
'ttlbeli' => (int)$beli * 38000,
'berasbawa' => $this->request->getvar('berasbawa'),
'ttlberas' => $this->request->getvar('berasbawa') + $this->request->getVar('berasbeli'),
'maal' => $this->request->getVar('maal'),
'berasinfaq' => $this->request->getVar('berasinfaq'),
'infaq' => $this->request->getvar('infaq'),
'fidyah' => $this->request->getVar('fidyah'),
'penerima' => $this->request->getVar('penerima'),
]
);
session()->setFlashdata('pesan', 'Upload Berhasil');
return redirect()->to('/');
This is the submit button
<button type="submit" class="btn btn-primary">Submit</button>
First make sure that you have added nama allow field into model and 2nd check that you are receiving data into getVar you can use return var_dump($beli); to check which data your are recieved. Cos nama is compulsory field in database.
Your /save url working properly

Add html to menu title in Drupal

I must have missed something. I can't figure out how to add some HTML into the title of the menu.
According to the menu api, I can't add options because I am using MENU_LOCAL_TASK, but then how? There is no say.
For example: if I try to make the title bold:
$items['whatever/tab2'] = array(
'title' => '<b>Tab 2</b>',
'type' => MENU_LOCAL_TASK,
);
This is not working.
You can use 'title callback' => 'example_title_callback',
Function to generate the title; defaults to t(). If you require only the raw string to be output, set this to FALSE.
You could use the Menu HTML module.

Apply a module layout to zfcuser

i'm working on zf2 and try to use 2 differents layouts. 1 layout for a public module and another one (private layout") for all the others. Its works pretty well but my zfcuser module in the public module use the other layout :/
i tried this :
'template_map' => array(
'zfc-user/user/login' => __DIR__ . '/../view/layout/blank.phtml', // blank is my public layout
),
Instead of get the form in my layout, i get my form in the public layout AND in the "private" layout ...
Does someone can help me ?
The code evan provides here http://blog.evan.pro/module-specific-layouts-in-zend-framework-2 will do what you need with one minor change, replace __NAMESPACE__ with 'ZfcUser' so that you're listening for ZfcUser controller actions
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach('ZfcUser', 'dispatch', function($e) {
// This event will only be fired when an ActionController under the ZfcUser namespace is dispatched.
$controller = $e->getTarget();
$controller->layout('layout/alternativelayout');
}, 100);
}
Added to composer.json
"evandotpro/edp-module-layouts": "1.0"
Created /module/Application/view/layout/blank.phtml
<?php echo $this->content;
Added this to /config/autoload/global.php
return array(
'module_layouts' => array(
'ZfcUser' => 'layout/blank'
));
Finally to /module/Application/config/module.config.php
'view_manager' => array(
'template_map' => array(
//add this line
'layout/blank' => __DIR__ . '/../view/layout/blank.phtml',

Drupal 6 textfield form element with ahah attribute

I have a form with a textfield element which when a user starts typing into I want to pre-populate a different element.
I've been using the #ahah attribute which works fine with the event property set to 'keyup' however I lose focus on the textfield element because the moment the 'keyup' event is fired the whole form is rebuilt due to ahah's behaviour.
I tried setting the event property to 'change' and that works nicely however in order for the 'change' event to fire I need to click away from the textfield - so from UI point of view I cannot expect users to click away from field just to get the results to display.
I'm not sure if it's possible to achieve what I want with AHAH which is fine but I'd like to stick with it if possible.
Happy to provide code if required and sorry if it's not clear, quite difficult to explain.
Thanks
Steve
The whole form shouldn't be re-rendered by the browser. That's precisely the idea AHAH, that you can update just part of a form. Make sure to set the "wrapper" attribute (of the #ahah attribute) to the ID (as in: the HTML attribute) of the DOM element that you want Drupal's JS functionality to update asynchronously.
For example:
<?php
function MYMODULE_some_ahah_enabled_form(&$form_state) {
$initial_markup = '<div>' . t('This content will be replaced') . '</div>';
$form['dynamic_thing'] = array(
'#type' => 'markup',
'#prefix' => '<div id="dynamic-thing">', // Set Drupal's AHAH wrapper to this ID
'#suffix' => '</div>',
'#value' => $initial_markup,
);
$form['field_which_will_trigger_ahah_behavior'] = array(
'#type' => 'textfield',
'#ahah' => array(
'path' => 'MYMODULE/path/to/ahah/callback',
'wrapper' => 'dynamic-thing',
'event' => 'keyup',
),
'#default_value' => 'Change me',
);
return $form;
}
/**
* Your menu callback (which is declared in your hook_menu()) which returns only the HTML that will replace the existing markup in $form['dynamic_thing'].
*/
function MYMODULE_ahah_callback() {
$output = '<div>New content for the dynamic thing</div>';
drupal_json(array('status' => TRUE, 'data' => $output));
exit();
}
Your "field_which_will_trigger_ahah_behavior" DOM element in the browser shouldn't lose focus, or be re-rendered in any way, unless there's something else causing some bug.

Drupal 6- 404 is not showing for menu item URL pattern implemented using hook_menu

I have a hook menu
$items['mypage'] = array(
'title' => t('My Page title'),
'description' => '',
'type' => MENU_CALLBACK,
'page callback'=> 'my_home_page',
'access arguments' => array('access content'),
);
Now when I access a page which is not existing like "mypage/blahblah" it will show my home page(ie http://www.mydomain.com/mypage/blahblah is rendering content of http://www.mydomain.com/mypage). Instead of this I need to show a 404 page.
Can anybody give comment on this ?
You can try to paste the following code in your page call back function "my_home_page"
if ('' != arg(1)){
drupal_not_found();
}
Thanks
Rahul

Resources