1

In the admin section of a component, i have this form:

enter image description here

I just added the checkboxes in the left following this Joomla API.

MyCode:

$i=$rows_num;
$checked    = JHTML::_( 'grid.id', $i, $voter["vid"] );
echo $checked;

And the Delete button shown in picture like that:

$bar->appendButton( 'Link', 'delete', 'Διαγραφή συγκεκριμένων ψήφων', 'index.php?option=com_exnetpolls&deleteit='.$isnotempty.'&gotcha=yo ');

The component isnt mine and the creator didnt use a controller ( every single action is executed in exnetpolls.php file ) so i created a new file getitdeleted.php and in exnetpolls.php i added this code :

exnetpolls.php (first file that getting executed)

if($_GET['deleteit']!="" && $_GET['deleteit']!=NULL){ 
    include("getitdeleted.php");
}

And in getitdeleted.php

<?php
defined('_JEXEC') or die('Restricted access');
echo "test";
$cid = JRequest::getVar('cid',array(),'','array');
var_dump($cid);
if(isset($_GET['gotcha'])){
echo "worked".$_GET['deleteit'];
//code to delete from db
unset($_GET['gotcha']);
}

I know the way im using is a bit retarted,but it works except that the:

$cid = JRequest::getVar('cid',array(),'','array');
var_dump($cid);

returns array(0) {}

Altough if i type in my browser :

index.php?option=com_exnetpolls&deleteit=18&gotcha=yo&cid[]=2

the var_dump returns : array(1) { [0]=> string(1) "2" }

I also noticed that i could somehow parse the value with jquery using the id of input, but i would like to do that if it was my last option.

<input id="cb15" name="cid[]" value="2278" onclick="Joomla.isChecked(this.checked);" title="Πλαίσιο ελέγχου για τη σειρά 16" type="checkbox">

I tried also to pass the cid[] somehow with the delete button like so:

$bar->appendButton( 'Link', 'delete', 'Διαγραφή συγκεκριμένων ψήφων', 'index.php?option=com_exnetpolls&deleteit='.$isnotempty.'&gotcha=yo&cid[] ');

But it doesnt work.Could a joomla specialist enlight me please on what am i doing wrong here ?

EDIT: forgot to mention that i would like to check before pressing the DELETE button if cid[]==NULL so i can change the value of $isnotempty . when i var_dump the $cid = JRequest::getVar('cid',array(),'','array'); in the file that i create the input, i get again a null array.

6
  • Do your checkboxes have correct markup? It should be something like <input id="cb0" name="cid[]" value="73" onclick="Joomla.isChecked(this.checked);" type="checkbox"> Jan 14, 2015 at 13:33
  • I allready mention it in the post ;) <input id="cb15" name="cid[]" value="2278" onclick="Joomla.isChecked(this.checked);" title="Πλαίσιο ελέγχου για τη σειρά 16" type="checkbox">
    – IseNgaRt
    Jan 14, 2015 at 13:38
  • Ah sorry missed it. Try to var_dump($_POST) just after echo "test". Is it containing cid array or it is also missing? Jan 14, 2015 at 14:00
  • Seems it is missing : var_dump($_POST)-> array(0) { }
    – IseNgaRt
    Jan 14, 2015 at 14:05
  • Wait , wait because i dont use a method="POST" somewhere. Should i ? My form is like that:<form action="" name="adminForm"> and i use the delete button to do the work. Should i put METHOD="POST" to my form, and make the delete button a submit button that would do the same stuff??
    – IseNgaRt
    Jan 14, 2015 at 14:11

1 Answer 1

1

Based on our comments I would suggest that your delete button invokes only GET action. That means all input fields are not processed. Try to use normal <form> with action="post" like:

<form action="<?php echo JRoute::_('index.php?option=com_exnetpolls&deleteit='.$isnotempty.'&gotcha=yo'); ?>" method="post" name="adminForm" id="adminForm">
3
  • POST:array(3) { ["cid"]=> array(1) { [0]=> string(4) "2273" } I think im gonna cry of joy. After 8 hours im redeemed! You are a lifesaver dude , thank you very much !
    – IseNgaRt
    Jan 14, 2015 at 14:32
  • A quick mini question, how could i check with this way if a checkbox is checked or not ?!
    – IseNgaRt
    Jan 14, 2015 at 14:33
  • 1
    You should have <input type="hidden" name="boxchecked" value="0" /> in your form and this value will be not zero when checkbox is checked. It is updated by onclick="Joomla.isChecked(this.checked);" function. Jan 14, 2015 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.