# CI4: form POST to same page, request method remains GET

**URL:** <https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367>\
**Category:** General PHP Help\
**Created:** [April 17, 2021, 4:25pm UTC](https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367 "2021-04-17T16:25:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BFlokstra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@BFlokstra](https://www.phphelp.com/u/BFlokstra)\
**Post date:** [April 17, 2021, 4:25pm UTC](https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367/1 "2021-04-17T16:25:24Z")

</div>

I’m using CodeIgniter 4 and hope someone here can help me.

I’m trying to post a form to the current page and process it there. To this end I addes a matched route to Routes.php:

```auto
$routes->match(['get', 'post'], 'klanten/(:segment)', 'Klanten::bewerk/$1'); 
```

I do not have a route set up that overwrites this route. Here is the full routes list:

```auto
$routes->match(['get', 'post'], 'soorten/(:segment)', 'Soorten::index/$1');
$routes->match(['get', 'post'], 'deurbel/(:segment)/(:segment)', 'Deurbel::index/$1/$2');
$routes->get('klanten', 'Klanten::index');
$routes->post('klanten/toevoegen', 'Klanten::toevoegen');
$routes->match(['get', 'post'], 'klanten/(:segment)', 'Klanten::bewerk/$1');
$routes->get('/', 'Dashboard::index'); 
```

When I post the form somehow the request method keeps coming back as get instead of post… Here is my form HTML:

```auto
<form action="/klanten/<?= esc($klant['slug']) ?>/" method="post">
                <div class="row">
                    <div class="col-12">
                        <div class="form-group">
                            <label for="naam">Naam: </label>
                            <input type="text" class="form-control" name="naam" id="naam" value="<?= $klant['naam'] ?>">
                        </div>
                        <div class="form-group">
                            <label for="woonplaats">Woonplaats: </label>
                            <input type="text" class="form-control" name="woonplaats" id="woonplaats" value="<?= $klant['woonplaats'] ?>">
                        </div>
                    </div>
                </div>
                 <?php if(isset($validation)): ?>
                     <div class="row">
                        <div class="alert alert-danger" role="alert">
                            <?= $validation->listErrors() ?>
                        </div>
                     </div>
                    <?php endif;?>
                    <div class="row">
                        <div class="row">
                            <div class="col-12 col-sm-4">
                                <button type="submit" class="btn btn-success">Opslaan</button>
                            </div>
                        </div>
                    </div>
            </form>
```

As you can see, I do have the forms method as post.  
The debug bar does show the route is there:

 ![debug-bar-routes-posting-form-remains-get](https://www.phphelp.com/uploads/default/original/2X/d/d0f0d9f298c67115262955c215332e0876b2663c.png)

By now I’m ready to smash my head against the wall, because I can’t figure out what is going on here. I’m hopinh you guys can help me and prevent me from doing that

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [April 18, 2021, 2:54pm UTC](https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367/2 "2021-04-18T14:54:37Z")

</div>

Not familiar with CodeIgniter really, but, one thing might be caching. Are you testing this on one machine?  
If so, you might want to dump your browser cache. I have seen where that has messed up results.  
Also, you might want to change your match([]) sections to have the POST first. I read somewhere that some calls might default to the first one. Might help.

---

<div class="post-metadata">

**Author:** ![BFlokstra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@BFlokstra](https://www.phphelp.com/u/BFlokstra)\
**Post date:** [April 29, 2021, 12:58pm UTC](https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367/3 "2021-04-29T12:58:07Z")

</div>

Thanks for your reply. Turned out I needed to remove the trailing slash from the url. That solved the problem.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [April 29, 2021, 3:29pm UTC](https://www.phphelp.com/t/ci4-form-post-to-same-page-request-method-remains-get/33367/4 "2021-04-29T15:29:26Z")

</div>

Oh my! That is odd. Glad you solved it!
