I have a telerik grid and would like to customize the footer template in such a way that the count is right under the sum like this:
Total: $XXXXXXX
Count: XXXXX
#model List
#(Html.Telerik().Grid(Model)
.Name("grd")
.NoRecordsTemplate(" ")
.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height(300))
.Footer(false)
.Columns(columns =>
{
columns.Bound(o => o.Number)
.Aggregate(ag => ag.Count());
columns.Bound(o => o.TotalCost)
.Aggregate(ag => ag.Sum())
.ClientFooterTemplate(
"<div>Total: <#= $.telerik.formatString('{0:c}', Sum) #></div>"
);
})
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Scrollable()
.Footer(true)
.HtmlAttributes(new { #class = ".t-grid .t-status" })
)
Thanks for your help.
You could try the following. Please be aware it is untested:
.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height(300))
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Columns(columns =>
{
columns.Bound(o => o.Number)
.Aggregate(ag => ag.Count())
.FooterTemplate(result => (result.Count == null ? "0" : result.Count.Format("{0:N0}")));
columns.Bound(o => o.TotalCost)
.Aggregate(ag => ag.Sum())
.FooterTemplate(result => (result.Sum == null ? "0.00" : result.Sum.Format("{0:N2}")));
})
If you wanted to see the Sum and Count on the footer beneath the same column:
.NoRecordsTemplate("No records available!")
.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height("auto"))
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Columns(columns =>
{
columns.Bound(o => o.TotalCost)
.HtmlAttributes(new { style = "text-align:right" })
.Format("{0:N2}")
.Aggregate(ag => ag.Sum().Count())
.FooterHtmlAttributes(new { style = "text-align:right" })
.FooterTemplate(result => string.Format("Total: ${0:N2}, Count: {1:N0}", result.Sum , result.Count))
.Width(60);
})
Related
I need to get the selected row in a detail grid. Here is the master grid:
#(
Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.AssessmentId).Hidden();
columns.Bound(c => c.AssessmentName).Width(250);
columns.Bound(c => c.CompetencyType).Width(80);
columns.Bound(c => c.CompanyName).Width(200);
columns.Bound(c => c.NumOfUnits).Width(50);
columns.Bound(c => c.CompetencyTypeId).Hidden();
columns.Bound(c => c.CompanyId).Hidden();
columns.Template(#<text></text>).Title("Actions").Width(150).ClientTemplate(
"<div class='btn btn-alt3' style='cursor: pointer;' onclick='downloadAssessment()'><i class='lnir lnir-download'></i>Download</div>" +
"# if('" + #IsiCanAdmin + "'== 'True' || ('" + #IsCompanyAdmin + "'== 'True' && CompetencyTypeId == 2 && CompanyId == " + User.companyId + ") ) {#" +
"<div class='btn btn-alt3' style='cursor: pointer;' onclick='editRow()'><i class='la la-edit'></i>Edit</div>" +
"<div id='deleteAssessment' class='btn btn-alt3' style='cursor: pointer;' onclick='deleteAssessment(this)'><i class='la la-trash'></i>Delete</div>" +
"# } #"
);
})
.Height(750)
.Scrollable()
.Sortable()
.Selectable()
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAssessmentSearch", "Config", new { area = "Competency" }))
.Model(m => m.Id(o => o.AssessmentId))
)
)
Here is the detail grid:
<script id="template" type="text/kendo-tmpl">
#(
Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentUnitModel>()
.Name("grid_#=AssessmentId#")
.Columns(columns =>
{
columns.Bound(o => o.UnitId).Hidden();
columns.Bound(o => o.UnitName).Width(350).Sortable(true);
columns.Bound(o => o.CompetencyType).Width(75);
columns.Bound(o => o.CompanyName).Width(200).Sortable(true);
columns.Bound(o => o.GapClosureThreshold).Width(50);
columns.Bound(o => o.NumEvidences).Width(50);
columns.Template(#<text></text>).Title("Actions").Width(150).ClientTemplate("#=editUnit(data)#");
})
.Scrollable()
.ClientDetailTemplateId("evidenceTemplate")
.DataSource(dataSource=>dataSource
.Ajax()
.Read(read=>read.Action("GetAssessmentUnits", "Config", new { area = "Competency", AssessmentId = "#=AssessmentId#" }))
.Model(m=>m.Id(o=>o.UnitId))
)
.ToClientTemplate()
)
Here is what I tried:
function editUnit(item) {
if ("#IsiCanAdmin" === "True") {
return "<div class='btn btn-alt3' style='cursor: pointer;' onclick='UnitEditRow(this)'><i class='la la-edit'></i>Edit</div>";
}
}
function UnitEditRow(item) {
var data1;
var grid = $("#grid").data('kendoGrid');
var allChildren = $(grid.element[0]).find('input.checkChild:selected')
$.each(allChildren, function () {
var detailRow = $(this).closest('tr');
var table = $(this).closest('div.k-grid');
var detailGrid = $(table).data('kendoGrid');
//var allSelected = detailGrid.select();
data1 = detailGrid.dataItem(detailRow);
});
var unitId = data1.UnitId;
openUnit(unitId)
}
Added a "DataBound" event to the detail grid to handle the hide/show of the button:
#(
Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentUnitModel>()
.Name("grid_#=AssessmentId#")
.Columns(columns =>
{
columns.Bound(o => o.UnitId).Hidden();
columns.Bound(o => o.UnitName).Width(350).Sortable(true);
columns.Bound(o => o.CompetencyType).Width(75);
columns.Bound(o => o.CompanyName).Width(200).Sortable(true);
columns.Bound(o => o.GapClosureThreshold).Width(50);
columns.Bound(o => o.NumEvidences).Width(50);
columns.Template(#<text></text>).Title("Actions").Width(150).ClientTemplate("<div class='btn btn-alt3 editClass' style='cursor: pointer;' onclick='editRow(this)'><i class='la la-edit'></i>Edit</div>");
})
.Selectable()
.Scrollable()
.ClientDetailTemplateId("evidenceTemplate")
.DataSource(dataSource=>dataSource
.Ajax()
.Read(read=>read.Action("GetAssessmentUnits", "Config", new { area = "Competency", AssessmentId = "#=AssessmentId#" }))
.Model(m=>m.Id(o=>o.UnitId))
)
.Events(e => e.DataBound("onDetailDataBound"))
.ToClientTemplate()
)
function onDetailDataBound() {
if ("#IsiCanAdmin" != "True") {
var editButtons = $(".editClass");
for (var i = 0; i < editButtons.length; i++) {
$(editButtons[i]).css("display", "none");
}
}
}
The use the button to find the closest row and table to get the dataItem:
function editRow(button) {
var buttonDiv = $(button)[0];
var row = $(buttonDiv).closest('tr');
var table = $(buttonDiv).closest(".k-grid");
var grid = $(table).data("kendoGrid");
var dataItem = grid.dataItem(row);
var unitId = dataItem.UnitId;
}
I am trying to :
1. Pull monitoring metrics of Logstash from an index.
2. Filter/Process with Logstash script.
3. Writing to InfluxDB.
The Logstash script looks like this:
input {
#logstash Metrics
http_poller {
urls => {
logstash_metrics => {
method => post
url => "http://elasticco-###############.com:80//%3C.monitoring-logstash-6-%7Bnow%2Fd%7D%3E//_search?filter_path=aggregations.source_node_ip.buckets"
headers => { Accept => "application/json" }
body => '{"query":{"bool":{"must":[{"range":{"timestamp":{"gte":"now-10m","format":"epoch_millis"}}}]}},"size":0,"aggregations":{"source_node_ip":{"terms":{"field":"source_node.ip","size":20},"aggregations":{"data":{"top_hits":{"size":1,"sort":[{"timestamp":{"order":"desc"}}]}}}}}}'
auth => { user => "elastic" password => "changeme" }
}
}
codec => json
schedule => { every => "10m"}
type => "logstash_metrics"
add_field => {
"region" => "west"
}
}
}
filter {
if [type] == "logstash_metrics"{
mutate {
rename => {
"[aggregations][source_node_ip][buckets]" => "root"
}
}
split { field => "[root]" }
mutate {
rename => {
"[root][data][hits][hits]" => "main_event"
}
}
split { field => "[main_event]" }
mutate {
rename => {
"[main_event][_source][cluster_uuid]" => "cluster_uuid"
"[main_event][_source][source_node][ip]" => "source_node_ip"
"[main_event][_source][source_node][host]" => "source_node_host"
"[main_event][_source][source_node][uuid]" => "source_node_uuid"
"[main_event][_source][logstash_stats][jvm][mem][heap_used_percent]" => "logstash_stats_jvm_mem_heap_used_percent"
"[main_event][_source][logstash_stats][jvm][mem][heap_used_in_bytes]" => "logstash_stats_jvm_mem_heap_used_in_bytes"
"[main_event][_source][logstash_stats][jvm][mem][heap_max_in_bytes]" => "logstash_stats_jvm_mem_heap_max_in_bytes"
"[main_event][_source][logstash_stats][jvm][uptime_in_millis]" => "logstash_stats_jvm_uptime_in_millis"
"[main_event][_source][logstash_stats][jvm][gc][collectors][young][collection_time_in_millis]" => "logstash_stats_jvm_gc_collectors_young_collection_time_in_millis"
"[main_event][_source][logstash_stats][jvm][gc][collectors][young][collection_count]" => "logstash_stats_jvm_gc_collectors_young_collection_count"
"[main_event][_source][logstash_stats][jvm][gc][collectors][old][collection_time_in_millis]" => "logstash_stats_jvm_gc_collectors_old_collection_time_in_millis"
"[main_event][_source][logstash_stats][jvm][gc][collectors][old][collection_count]" => "logstash_stats_jvm_gc_collectors_old_collection_count"
"[main_event][_source][logstash_stats][logstash][pipeline][batch_size]" => "logstash_stats_logstash_pipeline_batch_size"
"[main_event][_source][logstash_stats][logstash][pipeline][workers]" => "logstash_stats_logstash_pipeline_workers"
"[main_event][_source][logstash_stats][logstash][status]" => "logstash_stats_logstash_status"
"[main_event][_source][logstash_stats][logstash][host]" => "logstash_stats_logstash_host"
"[main_event][_source][logstash_stats][process][max_file_descriptors]" => "logstash_stats_process_max_file_descriptors"
"[main_event][_source][logstash_stats][process][cpu][percent]" => "logstash_stats_process_cpu_percent"
"[main_event][_source][logstash_stats][process][open_file_descriptors]" => "logstash_stats_process_open_file_descriptors"
"[main_event][_source][logstash_stats][os][cpu][load_average][5m]" => "logstash_stats_os_cpu_load_average_5m"
"[main_event][_source][logstash_stats][os][cpu][load_average][15m]" => "logstash_stats_os_cpu_load_average_15m"
"[main_event][_source][logstash_stats][os][cpu][load_average][1m]" => "logstash_stats_os_cpu_load_average_1m"
"[main_event][_source][logstash_stats][events][filtered]" => "logstash_stats_events_filtered"
"[main_event][_source][logstash_stats][events][in]" => "logstash_stats_events_in"
"[main_event][_source][logstash_stats][events][duration_in_millis]" => "logstash_stats_events_duration_in_millis"
"[main_event][_source][logstash_stats][events][out]" => "logstash_stats_events_out"
"[main_event][_source][logstash_stats][queue][type]" => "logstash_stats_queue_type"
"[main_event][_source][logstash_stats][queue][events_count]" => "logstash_stats_queue_events_count"
"[main_event][_source][logstash_stats][reloads][failures]" => "logstash_stats_reloads_failures"
"[main_event][_source][logstash_stats][reloads][successes]" => "logstash_stats_reloads_successes"
"[main_event][_source][logstash_stats][timestamp]" => "timestamp"
}
}
mutate {
remove_field => [ "root", "aggregations", "#timestamp", "#version" , "main_event"]
}
}
}
output {
if [type] == "logstash_metrics" {
stdout { codec => rubydebug }
influxdb {
host => "influx-qa-write.##########.com"
port => "8086"
user => "gt######00"
password => "hg3########1"
db => "logstash_statistics"
measurement => "logstash_health_test1"
data_points => {
"logstash_stats_events_in" => "%{logstash_stats_events_in}"
"logstash_stats_logstash_status" => "%{logstash_stats_logstash_status}"
"logstash_stats_logstash_pipeline_workers" => "%{logstash_stats_logstash_pipeline_workers}"
"logstash_stats_events_out" => "%{logstash_stats_events_out}"
"logstash_stats_events_duration_in_millis" => "%{logstash_stats_events_duration_in_millis}"
"logstash_stats_process_cpu_percent" => "%{logstash_stats_process_cpu_percent}"
"logstash_stats_jvm_mem_heap_used_in_bytes" => "%{logstash_stats_jvm_mem_heap_used_in_bytes}"
"logstash_stats_process_open_file_descriptors" => "%{logstash_stats_process_open_file_descriptors}"
"logstash_stats_jvm_uptime_in_millis" => "%{logstash_stats_jvm_uptime_in_millis}"
"logstash_stats_events_filtered" => "%{logstash_stats_events_filtered}"
"logstash_stats_jvm_mem_heap_used_percent" => "%{logstash_stats_jvm_mem_heap_used_percent}"
"logstash_stats_jvm_gc_collectors_young_collection_time_in_millis" => "%{logstash_stats_jvm_gc_collectors_young_collection_time_in_millis}"
"source_node_ip" => "%{source_node_ip}"
"logstash_stats_queue_events_count" => "%{logstash_stats_queue_events_count}"
"logstash_stats_reloads_failures" => "%{logstash_stats_reloads_failures}"
"logstash_stats_logstash_host" => "%{logstash_stats_logstash_host}"
"logstash_stats_jvm_gc_collectors_young_collection_count" => "%{logstash_stats_jvm_gc_collectors_young_collection_count}"
"logstash_stats_os_cpu_load_average_5m" => "%{logstash_stats_os_cpu_load_average_5m}"
"logstash_stats_jvm_gc_collectors_old_collection_time_in_millis" => "%{logstash_stats_jvm_gc_collectors_old_collection_time_in_millis}"
"source_node_uuid" => "%{source_node_uuid}"
"logstash_stats_os_cpu_load_average_15m" => "%{logstash_stats_os_cpu_load_average_15m}"
"logstash_stats_reloads_successes" => "%{logstash_stats_reloads_successes}"
"logstash_stats_logstash_pipeline_batch_size" => "%{logstash_stats_logstash_pipeline_batch_size}"
"source_node_host" => "%{source_node_host}"
"logstash_stats_jvm_gc_collectors_old_collection_count" => "%{logstash_stats_jvm_gc_collectors_old_collection_count}"
"logstash_stats_process_max_file_descriptors" => "%{logstash_stats_process_max_file_descriptors}"
"logstash_stats_jvm_mem_heap_max_in_bytes" => "%{logstash_stats_jvm_mem_heap_max_in_bytes}"
"cluster_uuid" => "%{cluster_uuid}"
"logstash_stats_queue_type" => "%{logstash_stats_queue_type}"
"logstash_stats_os_cpu_load_average_1m" => "%{logstash_stats_os_cpu_load_average_1m}"
"region" => "%{region}"
}
coerce_values => {
"logstash_stats_logstash_pipeline_workers" => "integer"
"logstash_stats_events_in" => "integer"
"logstash_stats_logstash_status" => "string"
"logstash_stats_events_out" => "integer"
"logstash_stats_events_duration_in_millis" => "integer"
"logstash_stats_process_cpu_percent" => "float"
"logstash_stats_jvm_mem_heap_used_in_bytes" => "integer"
"logstash_stats_process_open_file_descriptors" => "integer"
"logstash_stats_jvm_uptime_in_millis" => "integer"
"logstash_stats_events_filtered" => "integer"
"logstash_stats_jvm_mem_heap_used_percent" => "float"
"logstash_stats_jvm_gc_collectors_young_collection_time_in_millis" => "integer"
"source_node_ip" => "string"
"logstash_stats_queue_events_count" => "integer"
"logstash_stats_reloads_failures" => "integer"
"logstash_stats_logstash_host" => "string"
"logstash_stats_jvm_gc_collectors_young_collection_count" => "integer"
"logstash_stats_os_cpu_load_average_5m" => "float"
"logstash_stats_jvm_gc_collectors_old_collection_time_in_millis" => "integer"
"source_node_uuid" => "string"
"logstash_stats_os_cpu_load_average_15m" => "float"
"logstash_stats_reloads_successes" => "integer"
"logstash_stats_logstash_pipeline_batch_size" => "integer"
"source_node_host" => "string"
"logstash_stats_jvm_gc_collectors_old_collection_count" => "integer"
"logstash_stats_process_max_file_descriptors" => "integer"
"logstash_stats_jvm_mem_heap_max_in_bytes" => "integer"
"cluster_uuid" => "string"
"logstash_stats_queue_type" => "string"
"region" => "string"
}
send_as_tags => ["region","source_node_uuid"]
flush_size => 3000
idle_flush_time => 1
retention_policy => "rp_400d"
}
stdout {codec => rubydebug }
}
}
Sample output to the console (stdout) looks good and as expected:
{
"logstash_stats_events_in" => 621,
"logstash_stats_logstash_status" => "green",
"logstash_stats_logstash_pipeline_workers" => 16,
"logstash_stats_events_out" => 621,
"logstash_stats_events_duration_in_millis" => 4539,
"logstash_stats_process_cpu_percent" => 0,
"logstash_stats_jvm_mem_heap_used_in_bytes" => 170390792,
"logstash_stats_process_open_file_descriptors" => 259,
"type" => "logstash_metrics",
"logstash_stats_jvm_uptime_in_millis" => 310770160,
"logstash_stats_events_filtered" => 621,
"logstash_stats_jvm_mem_heap_used_percent" => 0,
"logstash_stats_jvm_gc_collectors_young_collection_time_in_millis" => 21586,
"source_node_ip" => "10.187.8.207",
"logstash_stats_queue_events_count" => 0,
"logstash_stats_reloads_failures" => 0,
"timestamp" => "2018-01-30T15:56:18.270Z",
"logstash_stats_logstash_host" => "ip-187-7-147.dqa.capitalone.com",
"logstash_stats_jvm_gc_collectors_young_collection_count" => 487,
"logstash_stats_os_cpu_load_average_5m" => 0.19,
"logstash_stats_jvm_gc_collectors_old_collection_time_in_millis" => 124,
"source_node_uuid" => "VmarsH2-RMO0HY2u2-A9EQ",
"logstash_stats_os_cpu_load_average_15m" => 0.13,
"logstash_stats_reloads_successes" => 0,
"logstash_stats_logstash_pipeline_batch_size" => 125,
"source_node_host" => "10.187.8.207",
"logstash_stats_jvm_gc_collectors_old_collection_count" => 1,
"logstash_stats_process_max_file_descriptors" => 16384,
"logstash_stats_jvm_mem_heap_max_in_bytes" => 32098877440,
"cluster_uuid" => "LkLw_ASTR7CVQAaX1IzDgg",
"logstash_stats_queue_type" => "memory",
"region" => "west",
"logstash_stats_os_cpu_load_average_1m" => 0.06
(Successfully the formatted output was generated)
But this above script is unable to write this to the Influx and the error logs shows this:
09:56:25.658 [[main]>worker0] DEBUG logstash.outputs.influxdb - Influxdb output: Received event: %{host} %{message}
Exception in thread "[main]>worker0" java.io.IOException: fails
at org.logstash.Event.getTimestamp(Event.java:140)
at org.logstash.ext.JrubyEventExtLibrary$RubyEvent.ruby_timestamp(JrubyEventExtLibrary.java:289)
at org.logstash.ext.JrubyEventExtLibrary$RubyEvent$INVOKER$i$0$0$ruby_timestamp.call(JrubyEventExtLibrary$RubyEvent$INVOKER$i$0$0$ruby_ti
mestamp.gen)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:306)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:136)
at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:60)
at org.jruby.ast.FCallTwoArgNode.interpret(FCallTwoArgNode.java:38)
at org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:74)
at org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:182)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:203)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
at org.jruby.ast.FCallOneArgNode.interpret(FCallOneArgNode.java:36)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at org.jruby.runtime.Interpreted19Block.evalBlockBody(Interpreted19Block.java:206)
at org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:157)
at org.jruby.runtime.Block.yield(Block.java:142)
at org.jruby.RubyArray.eachCommon(RubyArray.java:1606)
at org.jruby.RubyArray.each(RubyArray.java:1613)
Update: My logstash is able to communicate with InfluxDB (other scripts were working fine) and the environment versions I am using are : Logstash 5.4, InfluxDB 1.4.2, Java 8 (64 bit), logstash-output-influxdb 5.0.3 (output plugin) , Windows 7 Enterprise (64 bit).
Can someone suggest what is going wrong here ? Let me know if you require any further information.
Thanks !
Is it possible to create a module that outputs two tabs into the publish screen, or do I have two create another module to to create my second tab or just another tab.file.php file?
CODE
FILE: upd.my_module.php
class My_module_upd {
var $version = '1.0';
public function __construct(){
$this->EE =& get_instance();
}
public function install(){
$this->EE->load->dbforge();
$data = array(
'module_name' => 'My Module',
'module_version' => $this->version,
'has_cp_backend' => 'y',
'has_publish_fields' => 'y'
);
$this->EE->db->insert('modules', $data);
return true;
}
public function tabs(){
$tabs['tab_1'] = array(
'field_1' => array(
'visible' => TRUE,
'collapse' => FALSE,
'htmlbuttons' => TRUE,
'width' => '100%'
),
'field_2' => array(
'visible' => TRUE,
'collapse' => FALSE,
'htmlbuttons' => TRUE,
'width' => '100%'
)
);
$tabs['tab_2'] = array(
'field_1' => array(
'visible' => TRUE,
'collapse' => FALSE,
'htmlbuttons' => TRUE,
'width' => '100%'
),
);
return $tabs;
}
}
FILE: tab.my_module.php
class My_module_tab {
public function __construct(){
$this->EE =& get_instance();
}
public function publish_tabs($channel_id, $entry_id = ''){
$settings = array(
'field_1' => array(
'field_id' => 'field_1',
'field_label' => 'Field 1',
'field_type' => 'text',
'field_required' => 'n',
'field_data' => '',
'field_text_direction' => 'ltr',
'field_maxl' => 100,
'field_instructions' => '',
),
'field_2' => array(
'field_id' => 'field_2',
'field_label' => 'Field 2',
'field_type' => 'text',
'field_required' => 'n',
'field_data' => '',
'field_text_direction' => 'ltr',
'field_maxl' => 100,
'field_instructions' => '',
),
);
return $settings;
}
}
In the My_module_upd->tabs() method it looks like to can declare multiple tabs in the array but the My_module_tab class seems geared to controlling just one tab. Can anyone point me in the right direction?
I am trying to create a simple module in Drupal 6.20 as follows:
<?php
function example_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('This module implements an example form.');
}
}
function example_menu($may_cache) {
$items = array();
if ($may_cache)
{
$items[] = array(
'path' => 'example',
'title' => t('Example'),
'callback' => 'example_page',
'access' => TRUE,
'type' => MENU_NORMAL_ITEM
);
}
return $items;
}
function example_page() {
return drupal_get_form('example_page_form');
}
function example_page_form() {
$form['fullname'] = array(
'#type' => 'textfield',
'#title' => t('Enter your full name'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function example_page_form_submit($form_id, $form_values) {
...some code
}
But whenever i am typing in http://mysite.com/example, its getting redirected to 404. Please help. I am very new to Drupal technology. Is there ne more files needed for this apart from the .info and .module file?
Thanks.
Ive got the solution. For Drupal 6.X it menu hook should be as follows:
function example_menu() {
$items = array();
$items['example'] = array(
'title' => 'List',
'page callback' => 'example_page',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
return $items;
}
This is a module that I'm working on to create a custom filtered search. But i have no idea on getting the values of form type checkboxes... I searched but nothing yet!
<?php
function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => t('My form'),
'page callback' => 'my_module_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
return $items;
}
function my_module_form() {
return drupal_get_form('my_module_my_form');
}
function my_module_my_form($form_state) {
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Search'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Removes the #required property and
// uses the validation function instead.
$form['name']['first'] = array(
'#type' => 'textfield',
'#title' => t('Search'),
'#default_value' => "Keyword",
'#description' => "Please enter your keyword.",
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['filter'] = array(
'#type' => 'fieldset',
'#title' => t('Filter'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['name']['filter']['node_options'] = array(
'#type' => 'checkboxes',
'#title' => t('Default options'),
'#default_value' => variable_get('node_options', 0),
'#options' => array(
'31' => t('Chinese'),
'28' => t('South Indian'),
'18' => t('Pizza'),
),
'#description' => t('Filter the results.'),
);
$form['name']['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
// Adds a new button to clear the form. The #validate property
// directs the form to use a new validation handler function in place
// of the default.
/* $form['clear'] = array(
'#type' => 'submit',
'#value' => 'Reset form',
'#validate' => array('my_module_my_form_clear'),
);*/
return $form;
}
// This is the new validation handler for our Reset button. Setting
// the $form_state['rebuild'] value to TRUE, clears the form and also
// skips the submit handler.
function my_module_my_form_clear($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
//block
function my_module_block($op = 'list', $delta = 0, $edit = array()) {
$block = array();
switch ($op) {
case 'list':
$block[0]['info'] = t('Custom search form');
break;
case 'view':
switch ($delta) {
case 0:
$block['subject'] = t('Custom search');
$block['content'] = drupal_get_form('my_module_my_form');
break;
}
break;
}
return $block;
}
function my_module_my_form_submit($form, &$form_state) {
$redirect_url = 'search/node/';
$redirect_url .= ' category:' . $form_state['values']['filters'];
$redirect_url .= ' %' . $form_state['values']['first'] . '%';
$form_state['redirect'] = $redirect_url;
}
If you are trying to get the value for the form field that in the form builder is contained in $form['name']['filter']['node_options'], then in the submission handler you need to use $form_state['values']['node_options'].
Also the menu callback should be changed to
$items = array();
$items['my_module/form'] = array(
'title' => t('My form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_form'),
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
There is no need to define two functions, where the first call the second one, to define a form builder.