Here is a part of my cakephp view code:
</fieldset>
</form>
<?php
$account = new Account();
$account->insertPos();
?>
<button id="button" name="button" onClick="assign();" value="save"> Save Changes </button>
</body>
I need the php part to be executed only if the button is clicked, how can i check that the button is clicked inside my view and execute this php code…
Thank…
There’s no way to do this in the same PHP request. By the time the user sees the button in order to click it, the page has finished rendering, the request is over, and PHP’s job is complete.
You’ll need to send another request to the server to make this happen, either via submitting a regular form, or via Ajax. Here’s a simple non-Ajax solution (may require tweaking to fit with the rest of your code):