Create a button in a custom file (v2023)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
twuc
User
Posts: 77

Create a button in a custom file (v2023)

Post by twuc »

I've created a button in a custom file to carry out a specific action (and avoid displaying the edit page).

                    <form action="LeagueEdit/<?php echo $league_id ?>?season_id=<?php echo $season_id+1 ?>" method = "post"> 
                    <input type="submit" value="Season Roll-Forward" class='btn btn-app bg-white'>
                    </form>

but get an Invalid post request.
I'm not surprised from a security perspective, but where do I look to find out how to do this? phpmaker2023
Many thanks.


arbei
User
Posts: 9787

Post by arbei »


twuc
User
Posts: 77

Post by twuc »

Thank you. I've changed the code:

                    <form action="LeagueEdit" method = "post"> 
                        <input type="hidden" name="league_id" value="<?php echo $league_id ?>"><!-- comment -->
                        <input type="hidden" name="season_id" value="<?php echo $season_id+1 ?>"><!-- comment -->
                        <input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
                        <input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
                        <button type="submit" value="Season Roll-Forward" class='btn btn-app bg-white'>
                        <i class='fas fa-wand-magic-sparkles text-orange'></i><p> Season Roll-Forward</p>
                    </form>

I can see the parameters are correctly set, and 'check token for form post' is set, but now get redirected to the list page (status 302).
Am I missing something?


arbei
User
Posts: 9787

Post by arbei »

twuc wrote:

<form action="LeagueEdit" method ="post">

You have wrong "action" attribute value, you need to pass the primary key in the URL as route value (e.g. LeagueEdit/<?= urlencode($league_id) ?>).


twuc
User
Posts: 77

Post by twuc »

Thank you, that now takes me to the edit form and has answered my question.

What I hoped the code would do was submit the edit form with the parameter supplied and make use of existing server events. It's not the end of the world because I can create a custom file and execute the relevant server events which is probably a neater solution.

However, I have two remaining questions:
Firstly is it possible to pre-populate the fields in the Edit form with the input values?
Secondly, is it possible to submit and save 'LeagueEdit' without displaying the form using the parameter input values?


twuc
User
Posts: 77

Post by twuc »

My last reply,

However, I have two remaining questions:

calling a form from a form makes no sense at all! The way forward is to create a Custom File to do the updates.

Many thanks for your help.


Post Reply