Usually the form is POST, but in a single instance it is GET - cakephp

I do a standard pattern in my application - a link to /controller/delete/object_id, then a post form to "confirm", a check if $this->request->is('post') and if true - the controller deletes the object from database.
What is weird is that for a single, particular object_id, my browser (Firefox) forces the form to be a GET one. With any other object_id everything is ok, but with this particular one, despite all declarations within form tag and etc. brower generates a GET request.
Do you have any clue what this might be?! I even tried to use brower's private mode, because I thought it can be some garbage in browser cache, but the bug is still here.

I managed to bypass this problem:
define a specific action in form->create, pointing to your controller' method
add a hidden field with object_id
add some additional code in the controller method to get object_id from $this->request->data, because a hidden post field is not passed as an argument to method, as it is with GET method.
This way, to some unknown reason, it just works. Anyway, I still feel I'm doing something wrong. It's not as "clean" as I would expect.

Related

Trigger Rule with Filefield 'when field has changed' in Drupal 7

I've got a set of different rules that check if various field types have been updated 'after updating existing content'. The problem is that each one works fine, except for the only filefield type which will not work. The condition used is a 'NOT Data comparison' on the field checking the 'node-unchanged' version against the new 'node' version. This works with every other type of field and actions appropriately (that I have used at least), just not the filefield type; the rule just fires regardless of changes or not on the filefield.
I also found this post about a very similar problem: https://www.drupal.org/node/1011014#comment-10040082
I think I have the makings of a workaround, but I just wanted to check this with some fellow developers first as my PHP isn't the best.
If I were to enable the PHP module then add a condition in rules that checks the 'source' attribute to see if a new file has been added... would this work? The code I have is:
if (isset($object->field_FILEFIELD_NAME[0]['source'])) { //Check for new files }
I believe that $object is the node passed on by rule function as argument.
Is this a good idea/best approach? Any ideas or workarounds would be great.
Yes, you can use PHP for filefield checks as it is more clear (but always less secure). Here are my suggestions:
Create a Rule component (of type "Condition set (AND)") instead of a rule to do this check.
Use a parameter with your rule component (of type Node) so you have the $node available.
Use php to do the checks. Get the file data from the filefield using $node.
Create a normal rule (eg with event Before Saving Content) where you will use this component as a condition among others.
As you said you need to check for differences not for empty values, right? So instead of using isset you need to see if there is a different fid (which normally changes when there is a different file). Other methods are available and if you want to see which data can change do a dpm() to the filefield using devel module.
In order to get the unchanged value of the filefield use the same component on you main Rule but with the $unchanged node as parameter.

Controller fails if passed parm is "sys"

I am using a form in my index view to "GET" a query string for filtering my table. I end up with a URL like this, "/teams?company=sun".
This one works OK I use "$this->request->query('company');" to get the value. But if I change the parameter value to "sys" (e.g. company=sys) then I get a "404 - File or directory not found" error. I presume sys or system is a reserved word which is causing a problem somewhere.
Is this a bug or is it behaviour that I could catch and override?
IIS was doing SQLInjection attack prevention. I deleted the "SQLInjection" Rule from Request Filtering and it is working now.

protractor-js setting form action attributes

I have today tried to send the data via a form but the data must go in a post uri, Is there a way of appending the params to the form uri in a view which I could then submit a click to.
I have tried the code below. However,
driver.findElement(protractor.By.name('formelement')).setAttribute('action', attr);
returns Object has no method setAttribute
driver.findElement(protractor.By.name('externalFormData')).getText().then(function(result){
var attr = driver.findElement(proractor.By.name('formelement').getAttribute('action');
attr += result;
driver.findElement(protractor.By.name('formelement')).setAttribute('action', attr);
driver.findElement(protractor.By.name('submitRequest')).click();
});
Julie Ralph, the lead developer on protractor says its not (natively) possible here:
https://github.com/angular/protractor/issues/82
juliemr commented on Sep 12, 2013
A user wouldn't set an attribute, so it's not a feature of webdriver. Can you find a way of running your test manually just using your page? It seems that you might have to use angular and $http.post() instead of just relying on the 's action attribute.
Personally, this stinks a little. I have tests timing out because sendKeys is so slow on long text files. I'll keep you updated if I find a good work-around. Maybe there needs to be a 'pasteTextBlock' instead of 'sendKeys' ... by Julie's rationale a user might copy and paste rather than key in...

Cakephp 2.0 ReCaptcha plugin always wrong

I've taken a reCaptcha plugin from this guy
(github link of the plugin)
I've entered the following code form in my view:
[form creation]
[table]
[inputs]
[/table]
echo $this->Recaptcha->show(array('theme' => 'white'));
echo $this->Recaptcha->error();
[/form]
I've followed the steps suggested, and the reCaptcha window appears properly, but no matter what I enter in the captcha, it never gets verified and I always receive the 'message' field of beforeValidate (I've set it to "You've entered a wrong message" etc).
I'm not even sure how to debug it to see at which point it fails. Even if I just replace all the code in checkRecaptcha function with "return true" to try and skip the validation with the keys and just see if the rule itself is correct, it still remains the same, and I'm generally not getting any of the specific incorrect-captcha-sol messages that I read around.
Am I correct to assume that the only code I need inside my controller function (assuming I've already included the component and helper in the controller) is Configure::load('Recaptcha.key'); and no further manual validation checks?
(unfortunately I can't link you my whole project due to rights)
I had a similar issue. Try removing the 2 response and challenge field lines in the component and overwrite them with these:
$controller->$modelClass->set('recaptcha_response_field',
$controller->request->data['recaptcha_response_field']);
$controller->$modelClass->set('recaptcha_challenge_field',
$controller->request->data['recaptcha_challenge_field']);

CakePHP, extensions and layouts

I have a controller method that has long been handling JSON requests by parsing that extension, but now I need to open it up to cross domain ajax so I'd like to offer a JSONP variant by parsing that extension as well. I've already updated my routes.php file:
Router::parseExtensions( 'json', 'jsonp' );
So far all is well, but the happiness ends when the results are rendered. While the .json extension automagically picks up the json/default.ctp layout, the .jsonp content continues to adopt the non-specific default layout (and all of its unnecessary HTML content). I've tried using RequestHandler::setContent() to set the response content type to both json and js, but that doesn't seem to be what triggers the call to a given layout directory.
Does anyone know what does determine which content-specific layout directory is called? I tried creating jsonp/default.ctp and I've tried creating a js/default.ctp layout with my JSONP result, but nothing seems to engage. I just get the normal default.
Any insight into how extensions/content type are mapped to these layout directories would be much appreciated.
I've temporarily solved this by explicitly setting the layoutPath value:
$this->layoutPath = $params['url']['ext'];
This feels like one of those things where there must be a better solution, but maybe this is it. I'm going to leave the question open for a bit in the hopes that someone else has a solution that involves Cake's automagic.

Resources