Controller not called in a view (cake 3.5)[Fixed]


#1

Hi,
Since this morning I’m fighting that problem with might be obvious for everybody beside me.
I made a mail change form and for whatever reason, its controller is never called…

        <form class="form-horizontal">

    <?php echo $this->Form->create(null, ['url' => ['controller' => 'Profiles', 'action' => 'changemail']]); ?>
	<div class="col-md-6">

	<fieldset>
		<div class="form-group">
			<label for="inputEmail" class="col-sm-2 control-label"> New Email</label>

			<div class="col-sm-10">
				<input type="email" class="form-control" id="inputEmail" placeholder="Email">
			</div>
		</div>
	</fieldset>


    <?php echo $this->Form->button(__('Submit')); ?>
    <?= $this->Form->end() ?>

	</div>
</form>

and the associated controller resumed to its simplest expression: (ProfilesController.php)
public function changemail()
{
Debugger::dump(‘here…’);

}

I have no idea why it doesn’t work.

Thanks for your help!


#2
  1. look for html (page source in browser) and check if “url” created in ->Form->create() is reasonable.
  2. Call your action from address bar directly and check log/debug if it work that way.

#3

sadly it works…

I’m using Adminlte template if it does matter and login, registrations forms are working as it should.
It might be something trivial but I can’t wrap my head around it.

Thx


#4

sacha,

You have nested Form tags, which I believe is invalid HTML as the first form tag will be the active one. Once you remove the outside form tag your inner form will work.

I bet if you paste your browser rendered HTML source code on W3C’s HTML validator (https://validator.w3.org/) this would report that along with a closing DIV problem.


#5

That was it!
I overlooked at it for days and couldn’t see it !

thanks guys.


#6

Hi Sacha,
Can you please update the title of this thread and add “[Solved]” at the end?
Regards,
Philip.