Reputation: 3
I have some actions defined like "action = '[module]/[action]'" & submit. The result is '[currentUrl]/[module]/[action]' instead of '[module]/[action]', I can't figure out why, here's the code :
On the front :
<a href="<?php echo ( isset($disabledMajSuivi) && $disabledMajSuivi ? "#" : "javascript:showYesNoDialog('". addslashes(__('enquete.visu.msg.confirmation.majsuivi')). "', 'majSuivi')" ); ?>" >
<?php echo __('enquete.visu.majsuivi');?>
</a>
showYesNoDialog is a javascript function where first arg is the sentence displayed and second arg is callback function, so 'majSuivi' is called back and looks like this :
<script>
function majSuivi(response) {
if(response == 'yes') {
document.forms[0].action = "module_name/majsuivi";
document.forms[0].submit();
}
}
This has been debugged, the condition is true
.
The action 'majSuivi' (that is big) ends like this :
$this->redirect('enquete/visu?enq_id='.$enq_id
. (!is_null($personneMorale) ? '&pm_id='.$personneMorale->getPmId() : '') );
But no action is executed because of the wrong url (so actualy this part of code is kind of useless).
So when the URL should be : http://[baseUrl]/index.php/module_name/majsuivi
It is instead : http://[baseUrl]/index.php/enquete/visu/enq_id/24/menu_id/module_name/majsuivi
Where /index.php/enquete/visu/enq_id/24/menu_id/
was the current url just before calling 'majSuivi action.
Each time I click on the "a href" button, it adds the "module_name" to the URL like following :
click -> http://[baseUrl]/index.php/enquete/visu/enq_id/24/menu_id/module_name/majsuivi
click2 -> http://[baseUrl]/index.php/enquete/visu/enq_id/24/menu_id/module_name/module_name/majsuivi
click3 -> http://[baseUrl]/index.php/enquete/visu/enq_id/24/menu_id/module_name/module_name/module_name/majsuivi
etc ...
I don't think it comes from the routing.yml config file, but if someone thinks it could, I'll write the content of it.
Thanks for your help
Upvotes: 0
Views: 542
Reputation: 3
Thanks a lot, these are very useful informations, espacially the third option I think. Actualy I have different servers for testing before deploying. And I've observed two kind of behavior.
Behavior 1 : of every solutions I've tested, only document.forms[0].action = "/module_name/majsuivi";
is working.
Behavior 2 : of every solutions I've tested, none is working.
I've dug into php versions that were different from one testing server to one another, but putting two servers under the same PHP and Apache versions didn't make them have the same behavior about this issue.
As the deployment environment has behavior 1, I solved this issue for now by using the following javascript : document.forms[0].action = "/module_name/majsuivi";
.
All of what I explained before was going on my local server, which match with behavior 1.
I've already tested the first option : document.forms[0].action = ""; which doesn't work on any of the servers.
The second one gives me http://[baseUrl]/index.php/enquete/visu/enq_id/24/index.php/module_name/majsuivi
which is then not working, and I'm sure that if it doesn't work on local server, it won't on the others.
I have not tested the third solution as I kind of solved my issue for now, but it looks an effective solution, I think it should work. I'll update if I make use of it.
Thanks & Regards
Upvotes: 0
Reputation: 51
You should use something like this:
document.forms[0].action = "<?php echo url_for('module_name/majsuivi')?>";
or
document.forms[0].action = "/index.php/module_name/majsuivi";
or if you have this route in your routing.yml
document.forms[0].action = "<?php echo url_for('@your_route_name_from_yaml')?>";
Because 'module_name/majsuivi'
is a relative path and will be concatenated with your current url without /
at the beginning
Upvotes: 1