Yii Framework Forum: On Calling Delete Action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

On Calling Delete Action I got Error 400 Rate Topic: ****- 1 Votes

#1 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 16 June 2011 - 11:53 AM

when i fire action delete

/delete/8

i got

Error 400
Invalid request. Please do not repeat this request again.


:angry: :angry:
0

#2 User is offline   rurbinac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-August 10

Posted 16 June 2011 - 01:12 PM

View Postmoa7amed, on 16 June 2011 - 11:53 AM, said:

when i fire action delete

/delete/8

i got

Error 400
Invalid request. Please do not repeat this request again.


:angry: :angry:


Hi, in the code that gii generates for CRUD, the actionDelete starts with a check

if (Yii::app()->request->isPostRequest) {


So the delete action only works with a post (e.g. when called by submitting a form, not through a link). You can take out that validation out.
2

#3 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 16 June 2011 - 03:36 PM

You can indeed take out that check, but you probably shouldn't - it would leave your site open to XSS issues - any HTTP request which modifies something should be made using POST, and not GET.
Just create a POST form to trigger your delete action (or use ajax).
Rupert
2

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 16 June 2011 - 03:41 PM

View Postmoa7amed, on 16 June 2011 - 11:53 AM, said:

Error 400
Invalid request. Please do not repeat this request again.

You should be glad. Because that's the message hackers will receive when they've tried to wipe out your data via GET. ;)
"Less noise - more signal"
1

#5 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 19 June 2011 - 09:46 AM

Dear All

I still have this Error i made login and i need Delete row from grid view ..
what can i do ??

i make the delete from grid view is POST and not from URL Link ....
0

#6 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 529
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 19 June 2011 - 11:11 AM

View Postmoa7amed, on 19 June 2011 - 09:46 AM, said:

Dear All

I still have this Error i made login and i need Delete row from grid view ..
what can i do ??

i make the delete from grid view is POST and not from URL Link ....



Can you post your urlManager configuration with all rules?


1

#7 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 19 June 2011 - 11:25 AM

View Postphtamas, on 19 June 2011 - 11:11 AM, said:

Can you post your urlManager configuration with all rules?


Rules

public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
//'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('delete'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

*******************************************************************************
Url Manager



'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),



************************************************************************************
I Hope if u can help me in it
0

#8 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 529
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 19 June 2011 - 11:45 AM

Everything seems to be OK. Do you use Gii-generated code for delete action? Did you change anything in the code? Even the function parameter name?
1

#9 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 19 June 2011 - 12:56 PM

View Postphtamas, on 19 June 2011 - 11:45 AM, said:

Everything seems to be OK. Do you use Gii-generated code for delete action? Did you change anything in the code? Even the function parameter name?




yes i used Gii-gen and i didn t change anything ..

and i dont use Ajax .......and still cant delete ...
do u have solution ???
0

#10 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 19 June 2011 - 02:08 PM

Using CGridView you will only be able to delete if you are using Ajax - the link created for the delete button is a GET link to your delete action, and as such will fail when the delete action tests for POST request. If you use Ajax, then the request will be made using POST normally, and so should work - if it is not working, you'll need to check the ajax request using Firebug to see what errors you are getting.
Rupert
1

#11 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 21 June 2011 - 10:42 AM

View PostRedRabbit, on 19 June 2011 - 02:08 PM, said:

Using CGridView you will only be able to delete if you are using Ajax - the link created for the delete button is a GET link to your delete action, and as such will fail when the delete action tests for POST request. If you use Ajax, then the request will be made using POST normally, and so should work - if it is not working, you'll need to check the ajax request using Firebug to see what errors you are getting.




How I can Use Ajax with CGridview to delete ????????????
0

#12 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 21 June 2011 - 10:45 AM

Ajax delete is a default option on CGridView - it should only not work if you have disabled it somehow.

If it is enabled and your requests are still not working, you will have to check what is happening in Firebug!
Rupert
1

#13 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 21 June 2011 - 10:52 AM

View PostRedRabbit, on 21 June 2011 - 10:45 AM, said:

Ajax delete is a default option on CGridView - it should only not work if you have disabled it somehow.

If it is enabled and your requests are still not working, you will have to check what is happening in Firebug!



I saw in FireBug this Error


no element found
onload()22 (line 17)
for(i = 0; i < lis.length; i++)

0

#14 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 21 June 2011 - 10:56 AM

I'm afraid you'll have to be more explicit than that - we can't do all debugging for you...

What script in what file does this error pertain to? Have you followed it upstream to see what could be causing it?
Rupert
0

#15 User is offline   moa7amed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-May 11

Posted 21 June 2011 - 11:02 AM

View PostRedRabbit, on 21 June 2011 - 10:56 AM, said:

I'm afraid you'll have to be more explicit than that - we can't do all debugging for you...

What script in what file does this error pertain to? Have you followed it upstream to see what could be causing it?


sorry sorry this error from other place but i still have error in delete is say


Error 400
Invalid request. Please do not repeat this request again.
0

#16 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 529
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 21 June 2011 - 12:16 PM

View Postmoa7amed, on 21 June 2011 - 11:02 AM, said:

sorry sorry this error from other place but i still have error in delete is say


Error 400
Invalid request. Please do not repeat this request again.

First check in Firebug if all .js files loaded when opening page that contains gridview.
0

#17 User is offline   yancho 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-December 10

Posted 02 August 2011 - 07:34 AM

I had similiar problem when jquery.ba-bbq.js was loaded(or not loaded at all) before jquery.js.
0

#18 User is offline   nirmalroka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 10-July 12
  • Location:Kathmandu Nepal

Posted 23 November 2012 - 02:47 AM

Hi I had faced this problem. I had done this in way as below.

<?php 

echo CHtml::ajaxLink('Delete',
		Yii::app()->createUrl('/quiz/delete/id/'.$rquiz->id),
		array(
				'type'=>'post',
				'data' => array('id' =>$rquiz->id,'type'=>'delete'),
				'update'=>'message',
				'success' => 'function(response) {
				$(".message").html(response);
				$(".rquiz_'.$rquiz->id.'").remove();
}',
		),
		array( 'confirm'=>'Are you sure to delete this question',)
);



?>




I hope this could help you.

Yii::app()->createUrl('/quiz/delete/id/'.$rquiz->id)

is important for you.

In ajax link above method type is post so in delete action

	public function actionDelete($id)
	{
		
		if(Yii::app()->request->isPostRequest)
		{
			// we only allow deletion via POST request
			$this->loadModel($id)->delete();
			
			if(isset($_POST['type']))
				$this->redirect(array('/site/index'));
		
			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if(!isset($_GET['ajax']))
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		
	}




I hope this will work.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users