Yii - form with CMultiFileUpload won't submit files - file

I need some help with a little strange problem.
My problem is that submit button does not submit files to controller when using CMultiFileUpload.
I have this very simple view to upload multiple files:
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));?>
<div class="row">
<?php echo $form->labelEx($model,'sourceCode'); ?>
<?php
$this->widget('CMultiFileUpload', array(
'model'=>$model,
'name' => 'sourceCode',
'attribute'=> 'sourceCode',
'max'=>5,
'accept' =>'zip',
'duplicate' => 'Duplicate file!',
'denied' => 'Invalid file type',));
echo $form->error($model,'sourceCode');?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget();?>
Here is my model:
class UploadSolutionForm extends CFormModel
{
public $sourceCode;
public function rules()
{
return array(
array('sourceCode', 'file', 'types'=>'zip', 'allowEmpty'=>false, 'wrongType'=>'Only .zip files allowed'),
);
}
public function attributeLabels()
{
return array(
'sourceCode' => 'Uploaded file',
);
}
}
And here is probably the simplest action ever:
public function actionUpload()
{
$model = new UploadSolutionForm();
if(isset($_POST['UploadSolutionForm']))
{
echo 'Got it!';
}
$this->render('solve',array('model'=>$model));
}
But when I click on submit it does not echo anything, but it does with this code (CMultiFileUpload is replaced with fileField):
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));?>
<div class="row">
<?php echo $form->labelEx($model, 'sourceCode');?>
<br><?php echo $form->fileField($model, 'sourceCode');?>
<?php echo $form->error($model, 'sourceCode');?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php
$this->endWidget();?>
Can someone tell me what's wrong?
Thanks in advance...

Try this it works
In your View file specify action attribute in form widget as shown in the below code
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'action'=>Yii::app()->createAbsoluteUrl('yourcontrollername/actionname'),
'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));?>
<div class="row">
<?php $this->widget('CMultiFileUpload',array(
'name'=>'files',
'accept'=>'jpg|png',
'max'=>3,
'remove'=>Yii::t('ui','Remove'),
//'denied'=>'', message that is displayed when a file type is not allowed
//'duplicate'=>'', message that is displayed when a file appears twice
'htmlOptions'=>array('size'=>25),
)); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget();?>
In yourController actionUplaod as shown below
public function actionUpload(){
echo "hi";
var_dump($_FILES['files']);
}

Related

Cakephp 3 Three Column View based on an Id

This is Cakephp 3.5, So I have three businesses 1, 2, 3. I have a view to show Estimated Revenue From Fees.
On the index page I have a three column Div
<div class="row">
<div class="col-md-12">
<h2><?= __('Estimated Revenue From Fees') ?></h2>
<div class="row">
<div class="column">
<h4>Business One</h4>
<ul>
<?php foreach ($estimatedRevenueFromCFeesBiz1 as $estimatedRevenueFromFeeBiz1): ?>
<li class="actions">
<?= $this->Html->link(__( h($estimatedRevenueFromFeeBiz1->year), ['action' => 'view', $estimatedRevenueFromFeeBiz1->id]) ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="column">
<h4>Business Two</h4>
<?php foreach ($estimatedRevenueFromFeesNauBiz2 as $estimatedRevenueFromFeeBiz2): ?>
<li class="actions">
<?= $this->Html->link(__( h($estimatedRevenueFromFeeNauBiz2->year), ['action' => 'view', $estimatedRevenueFromFeeBiz2->id]) ?>
</li>
<?php endforeach; ?>
</div>
<div class="column">
<h4>Business Three</h4>
<?php foreach ($estimatedRevenueFromCourseFeesUa as $estimatedRevenueFromCourseFeeUa): ?>
<li class="actions">
<?= $this->Html->link(__( h($estimatedRevenueFromFeeBiz3->year), ['action' => 'view', $estimatedRevenueFromFeeBiz3->id]) ?>
</li>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
In my controller I've set up like this:
public function index()
{
$estimatedRevenueFromFeesBiz1 = $this->EstimatedRevenueFromFeesBiz1->find('list', array( 'conditions' => 'business_id' == 1));
$estimatedRevenueFromFeesBiz2 = $this->EstimatedRevenueFromFeesBiz2->find('list', array( 'conditions' => 'business_id' == 2));
$estimatedRevenueFeesBiz3 = $this->EstimatedRevenueFromFeesBiz3->find('list', array( 'conditions' => 'business_id' == 1));
$this->set(compact('estimatedRevenueFromFeesBiz1', 'estimatedRevenueFromFeesBiz2', 'estimatedRevenueFromFeesBiz3'));
}
I'm getting a Call to a member function find() on boolean
Error in: ROOT\src\Controller\EstimatedRevenueFromCourseFeesController.php, line 26 which is the
$estimatedRevenueFromFeesBiz1 = $this->EstimatedRevenueFromFeesBiz1->find('list', array( 'conditions' => 'business_id' == 1)); line.
I figured it out. I changed the controller back to just calling the whole table:
public function index()
{
$this->paginate = [
'contain' => ['Businesses']
];
$estimatedRevenueFromFees = $this->paginate($this->EstimatedRevenueFromFees);
$this->set(compact('estimatedRevenueFromFees'));
}
I then added a condition into the index.ctp file:
<h4>Business One</h4>
<ul>
<?php foreach ($estimatedRevenueFromFees as $estimatedRevenueFromFee): ?>
<?php if ($estimatedRevenueFromFee['business_id'] == 1): ?>
<li class="actions">
<?= $this->Html->link(__( h($estimatedRevenueFromFee->year), ['action' => 'view', $estimatedRevenueFromFee->id]) ?>
</li>
<?php else: ?>
<?php continue; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Well, based on what you said and on your own answer, it looks like what you were trying to do was this:
public function index() {
$estimatedRevenueFromFeesBiz1 = $this->EstimatedRevenueFromFees->find('list', ['conditions' => ['business_id' == 1]]);
$estimatedRevenueFromFeesBiz2 = $this->EstimatedRevenueFromFees->find('list', ['conditions' => ['business_id' == 2]]);
$estimatedRevenueFeesBiz3 = $this->EstimatedRevenueFromFees->find('list', ['conditions' => ['business_id' == 1]]);
$this->set(compact('estimatedRevenueFromFeesBiz1', 'estimatedRevenueFromFeesBiz2', 'estimatedRevenueFromFeesBiz3'));
}
What changes is your condition (business_id). But you are always querying over the same table (EstimatedRevenueFromFees).
Bare in mind that in your solution you are paginating. So you might end up having every record in a page with a certain business_id, or whatever combination.

How to get url params in cakephp?

I am using cakephp 2.6.7:
I have a password reset url like:
http://www.jegeachi.com/resellers/resetpw/9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12/
Here resellers is the controller and resetpw is the action and 9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12 is the argument I want to pass into resetpw function.
Now in resetpw.ctp:
<style type="text/css">
.alert {
padding: 6px;
margin-bottom: 5px;
border: 1px solid transparent;
border-radius: 4px;
text-align: center;
}
.alert.alert-error {
background: #A9B0B5;
color: #EF5858;
font-weight: normal;
}
</style>
<div class="page-content-wrapper">
<div class="page-content">
<!-- BEGIN PAGE CONTENT-->
<div class="content">
<!-- BEGIN LOGIN FORM -->
<?php
echo $this->Form->create('Reseller', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'class' => 'login-form',
'url' => array('controller' => 'resellers', 'action' => 'resetpw')
)
);
?>
<h3 class="form-title">Type your new password</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span>
Enter your new password first. </span>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">New Password</label>
<div class="input-icon">
<i class="fa fa-lock"></i>
<?php
echo $this->Form->input(
'password', array(
'class' => 'form-control placeholder-no-fix',
'type' => 'password',
'autocomplete' => 'off',
'placeholder' => 'New Password'
)
);
?>
</div>
</div>
<div class="form-actions">
<?php
echo $this->Form->button(
'Reset Password <i class="m-icon-swapright m-icon-white"></i>', array(
'class' => 'btn blue pull-right',
'type' => 'submit',
'escape' => false
)
);
?>
</div>
<?php echo $this->Form->end(); ?>
<!-- END LOGIN FORM -->
</div>
<!-- END PAGE CONTENT -->
</div>
</div>
<!-- END CONTENT -->
Inside resellers action:
function resetpw($a){
$this->layout = "public-login";
$this->loadModel('Reseller');
if ($this->request->is('post')) {
echo 'a : '.$a;
pr($this->params['url']); exit;
$a = func_get_args();
$keyPair = $a[0];
$key = explode('BXX', $keyPair);
$pair = explode('XXB',$key[1]);
$key = $key[0];
$pair = $pair[1];
$password = $this->request->data['Reseller']['password'];
unset($this->request->data['Reseller']['password']);
$uArr = $this->Reseller->findById($pair);
if($uArr['Reseller']['resetkey'] == $key) {
$this->Reseller->read(null, $pair);
$this->Reseller->set('password', $password);
if($this->Reseller->save()) {
$msg = ' <div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Your password has been reset</strong>
</div>';
} else {
$msg = ' <div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
Something has gone wrong. Please try later or <strong>sign up again</strong>
</div>';
}
} else {
$msg = ' <div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Invalid link.Please check your reset link</strong> Invalid link.Please check your reset link
</div>';
}
$this->Session->setFlash($msg);
$this->redirect(array('controller'=>'resellers', 'action' => 'login'));
}
}
Here I want to catch the url data 9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12
But none of the following printing my data:
echo 'a : '.$a;
pr($this->params['url']); exit;
How can I get this url value.
As I said in one of my comments on your previous questions, you should first read the docs. What you are doing in this action is wrong on couple of levels, in cakephp sense. Normally you would get to this action by url I suppose
.../resellers/resetpw/9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12/
and by that you would already have that action argument in your controller:
public function resetpw($a = null)
Then you would check if $a is not null since you can't reset password without some kind of token. In your action $a already has this for value 9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12.
No need to use something like this:
$a = func_get_args();
Second thing, you should name arguments to be meaningful, $a doesn't mean nothing, but $token or something similar would make much difference.
There are multiple ways of doing it. In your function below (not writing entire one) you are trying to get the url argument in $a but you are passing parameter instead. Hence $a has no value
function resetpw($a){
$this->layout = "public-login";
$this->loadModel('Reseller');
if ($this->request->is('post')) {
echo 'a : '.$a; //$a will have no values here
pr($this->params['url']); exit;
In your case you need catch params like below
$a = $this->params['passed'][0];
Or to get argument your URL should be like below
http://www.jegeachi.com/resellers/resetpw?9610f4e33d96ad6189c5a779ab90f10aBXX1066056669XXB12/
so that you can collect it in $a. Hope this helps to you!
I solved this by removing 'url' in Form.
I changed
<?php
echo $this->Form->create('Reseller', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'class' => 'login-form',
'url' => array('controller' => 'resellers', 'action' => 'resetpw')
)
);
?>
To
<?php
echo $this->Form->create('Reseller', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'class' => 'login-form',
)
);
?>
Now it works. When you set url then parameter in url is removed.

User login null error

I am using cakephp 2.1 and I used login action in UsersController as follows.
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Invalid email or password, try again', 'default/flash_error');
}
}
}
And the login.ctp code is as follows.
<?php echo $this->Form->create('User', array('class' => 'form')); ?>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<?php echo $this -> Form -> text('email', array('id' => 'inputEmail', 'placeholder' => 'Email')); ?>
<?php echo $this -> Form -> error('email', null, array('wrap' => 'span', 'class' => 'help-block')); ?>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<?php echo $this -> Form -> password('password', array('id' => 'inputPassword', 'placeholder' => 'Password')); ?>
<?php echo $this -> Form -> error('password', null, array('wrap' => 'span', 'class' => 'help-block')); ?>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"/>
Remember me </label>
<?php echo $this->Form->button('Sign in', array('type' => 'submit', 'class' => 'btn')); ?>
</div>
</div>
<?php echo $this->Form->end(); ?>
When the form get submitted with email and password, the user is not able to login so its showing an error 'Invalid email or password, try again'. Even I am passing the $this->request->data['User'] into $this->Auth->login() method and debugged $this->Session->read(Auth.User.id). Its giving me null. Please give me a solution for this.
You can try passing $this->request->data into the $this->Auth->login() method. It's not a great way to do it (see this post: CakePHP Auth Component Not logging in when using $this->Auth->login();), but it works for me. Have you debugged $this->Auth->login()?

cakephp no id passed to Form

I have two forms, one to edit room details and the other to edit Extras. Within the forms I pull in a file upload and pass in the id. For some reason one requires a url and the id does not get passed in. Both have the same code. Can see why they are differnt.
Room form
<div class="boxgrid grid_8">
<?php echo $this->element('attachments',array('control'=>'upgrades','id'=>$this->data['AddOn']['id'],'att'=>$this->data['Attachment'])); ?>
</div>
Room upload
Form->create('Room', array('type' => 'file'));?>
<legend><?php __('Upload Room Images'); ?></legend>
<?php
echo $this->Form->input('id');
?>
<input type="hidden" name="data[Attachment][0][model]" value="Room" id="Attachment0Model" />
<input type="hidden" name="data[Attachment][0][group]" value="attachment" id="Attachment0Group" />
<div class="input file required"><input type="file" name="data[Attachment][0][file]" class="" id="Attachment0File" /></div>
<div class="submit"><button>Upload</button></div>
<div>Upload files</div>
Extras Form
<div class="boxgrid grid_8">
<?php echo $this->element('attachments',array('control'=>'upgrades','id'=>$this->data['AddOn']['id'],'att'=>$this->data['Attachment'])); ?>
</div>
Extras Upload
Form->create('Upgrade', array('type' => 'file','url'=>'/admin/upgrades/addfiles','id'=>'AddOnAdminAddfilesForm'));?>
<legend><?php __('Upload Addon Images'); ?></legend>
<?php
echo $this->Form->input('id');
?>
<input type="hidden" name="data[Attachment][0][model]" value="AddOn" id="Attachment0Model" />
<input type="hidden" name="data[Attachment][0][group]" value="attachment" id="Attachment0Group" />
<div class="input file required"><input type="file" name="data[Attachment][0][file]" class="" id="Attachment0File" /></div>
<div class="submit"><button>Upload</button></div>
<div>Upload files</div>
Javascript on each form:
<script type="text/javascript">
$(document).ready(function() {
$("div#uploader").resloader();
$("div#uploader").load('<?=BASE_URL?>/admin/upgrades/addfiles/<?=$this->data['AddOn']['id']?>',null,function(){}).fadeIn();
Upgrades Contoller
function admin_addfiles($id = null) {
$this->layout = null;
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Add On', true));
$this->redirect(array('controller' => 'upgrades', 'action' => 'index'));
}
if (!empty($this->data)) {
$this->layout = null;
//if(empty($this->data['AddOn']['id'])){unset($this->data['AddOn']);}
// restructure data for uploader plugin // NEED TO GET RID OF THIS ? MOVE IT
$tmp_file = $this->data['Attachment'][0]['file'];
$tmp_file['extension'] = array_reverse(explode('.', $tmp_file['name']));
$tmp_file['extension'] = $tmp_file['extension'][0];
$tmp_file['title'] = strtolower(substr($tmp_file['name'],0,(0-strlen('.'.$tmp_file['extension']))));
$this->data['Attachment'][0]['alternative'] = ucwords(str_replace('_',' ', $tmp_file['title']));
if ($this->AddOn->saveAll($this->data, array('validate' => 'first'))) {
$id = $this->AddOn->Attachment->getLastInsertID();
$att = $this->AddOn->Attachment->query("SELECT * from attachments WHERE id = ".$id);
$this->set('attachment',$att[0]['attachments']);
} else {
$tmp_file['name'] = 'INVALID FILE TYPE';
}
//debug($this->data);
$this->set('file', $tmp_file);
$this->RequestHandler->renderAs($this, 'ajax');
$this->render('../elements/ajax');
}
if (empty($this->data)) {
$this->data = $this->AddOn->read(null, $id);
}
}
}
Your problem is with the $this->data. Check how it is filled in your controller.
Both views are NOT the same, the main difference is in the create form.
Form->create('Room', array('type' => 'file'));?>
Form->create('Upgrade', array('type' => 'file','url'=>'/admin/upgrades/addfiles','id'=>'AddOnAdminAddfilesForm'));?>
As you can see, one has the first parameter 'Room' and the other one is 'Upgrade', this IS important since you call the id like this
echo $this->Form->input('id');
Cake expects that for the first case you have something like, $this->data['Room']['id'] and the second one $this->data['Upgrade']['id']
If you pass from the controller your id variable like this
$this->set('id',$id);
then in the view you can do somthing like this
<?php
echo $this->Form->input('id', array('value'=>$id, 'type'=>'hidden'));
?>
Hope this solves your answer, if not, please post the $this->data value of each and the part of the controller where you assign $this->data

CakePHP - Use JQuery/Ajax to increment an entry in the Db and update a DIV with the result

First all, I am still learning CakePHP and I am close to ZERO using JQuery.
I would like to get help for the following problem I am having:
I have an Articles_Controller a Comments_Controller and Users_Controller
Currently my articles_controller display an article and its comments are loaded on that page
Whoever user inputted the comment will also appear along with his/her image
On each comment I have added a like/dislike button.
Example:
Right now, however, I am only able to display it. What I wanted to accomplish is to use JQuery so that when a user clicks on the Thumbs Up or Thumbs Down image the like and disliked fields are automatically updated in the Db. Also, using JQuery I would like to update those same values in the View. Please my code below and thank you for your help.
articles/view.ctp
<div id="articles_comments">
<p>
Comments
</p>
<?php
foreach($comments as $comment){
?>
<div id="articles_comments_user">
<img src="<?php echo $comment['User']['image']; ?>">
<p>
<?php
$created = $comment['Comment']['created'];
echo $comment['User']['first_name'];
echo " ";
echo $comment['User']['last_name'];
echo " ";
//echo $comment['Comment']['created'];
echo $this->Time->timeAgoInWords(
$comment['Comment']['created'],
array(
'end'=>'+150 years'
)
);
?>
<p>
</div>
<div id="articles_comments_comment">
<table>
<tr>
<td style="width:85%">
<?php echo $comment['Comment']['comment'];?>
</td>
<td style="width:15%;border-left:solid thin teal;">
<div style="float:left;">
<?php echo $comment['Comment']['liked'];?>
<img width="20" src="/img/icons/thumb-up-icon.png"
</div>
<div style="float:right;margin-left:10px;">
<?php echo $comment['Comment']['disliked'];?>
<img width="20" src="/img/icons/thumb-down-icon.png">
</div>
</td>
</tr>
</table>
</div>
<?php
}
?>
<div class="articles_add_comment" id="formUpdateID">
<hr style="width:100%"><br>
<div style="float:left">
<h3>Seu Commentario:</h3>
<?php
echo $form->create(
'Comment',
array(
'url'=>array(
'controller'=>'articles',
'action'=>'view',
$article['Article']['id']
),
'class' => 'articles_form',
'id' => 'loginForm'
)
);
echo $form->input(
'Comment.comment',
array(
'label' => false,
'type' => 'textarea',
'div' => 'articles_comments_textarea',
'cols' => 90,
'rows' => 3
)
);
?>
</div>
<div style="float:right">
<?php
echo $this->Form->submit(
'Send',
array(
'class' => 'articles_comments_button'
)
);
echo $form->end();
?>
</div>
<div class="ajax-save-message">
<?php echo $this->Session->flash(); ?>
</div>
</div>
</div>
Comments is generated from the Articles View action
I was able to fix my problem by the following upon some research and try outs:
View file
<?php foreach $commments as $commment{ ?>
// .............................................................................
<td style="vertical-align:middle;border-left:solid thin teal;padding-left:5px;">
<div class="voteup" style="margin-left:10px;float:left;width:55px;">
<p style="display:none;float:left">
<?php echo $comment['Comment']['id']; ?>
</p>
<div style="float:left" id="article_thumbsUp">
<?php echo $comment['Comment']'liked'];?>
</div>
<img width="20" src="/img/icons/thumb-up-icon.png">
</div>
<div class="votedown" style="float:left;width:55px;">
<p style="display:none;float:left">
<?php echo $comment['Comment']['id']; ?>
</p>
<div style="float:left" id="article_thumbsDown">
<?php echo $comment['Comment']'disliked'];?>
</div>
<img width="20" src="/img/icons/thumb-down-icon.png">
</div>
</td>
// ...............................................................................
<?php } ?>
jQuery I used
<script>
$(document).ready(function(){
$(".voteup").click(function() {
var Id = $(this).children("p").text();
$(this).children("#article_thumbsUp").load("/comments/voteup/"+Id);
});
});
</script>
<script>
$(document).ready(function(){
$(".votedown").click(function() {
var Id = $(this).children("p").text();
$(this).children("#article_thumbsDown").load("/comments/votedown/"+Id);
});
});
</script>
And both of my actions in my comments_controller.php
function voteUp($id = null){
$this->autoRender = false;
if($this->RequestHandler->isAjax()){
$this->Comment->id = $id;
if($this->Comment->saveField('liked',$this->Comment->field('liked')+1)){
}
}
$newValue = $this->Comment->findById($id);
return $newValue['Comment']['liked'];
}
function voteDown($id = null){
$this->autoRender = false;
if($this->RequestHandler->isAjax()){
$this->Comment->id = $id;
if($this->Comment->saveField('disliked',$this->Comment->field('disliked')+1)){
}
}
$newValue = $this->Comment->findById($id);
return $newValue['Comment']['disliked'];
}
This is my entire code in detail and hopefully it can help someone else. This is the way I know how to do, and if you have any better way, I was be glad to know. Thanks a lot. THIS WORKS GREAT. I JUST NEED TO ADD A FEW MORE THINGS TO THIS SYSTEM, SUCH AS ONLY ALLOW REGISTERED USERS TO VOTE AND ONLY ONCE PER COMMENT. THAT WILL INVOLVE CREATING ANOTHER TABLE TO TRACK THAT.
Personally, I would create actions in the Comments_Controller, voteup and votedown. Then, make the thumbs up and thumbs down images link to /comments/voteup/id, etc.
After doing this, use jQuery to prevent a page reload when they're clicked, as such...
<a class="voteup" href="<?php echo $this->base;?>/comments/voteup/<?php echo $comment['Comment']['id'];?>">
<img ... />
</a>
<script>
$(".voteup").click(function(e) {
e.preventDefault();
$.ajax({
url: $(this).attr('href),
success: function() {
// Update vote counter
}
});
});
</script>
I'm sure you can piece together the rest.

Resources