Invalid post request

Hi
within a custom file i am trying to upload a file using

<form enctype="multipart/form-data" id="proposal_form" method="post" class="form-horizontal">
<input type="hidden" name="token" value="<?= CurrentPage()->Token ?>">
<input type="file" name="spreadsheet" id="file" size="150">
<button type="submit" class="btn btn-danger" name="submit" value="Import">Upload</button>

but when i select the file and submit i get the following message[2021-03-11T17:46:36.426803+00:00] log.DEBUG: 400 Bad Request Type: Slim\Exception\HttpBadRequestException Code: 400 Message: Invalid post request File: /var/www/html/src/PermissionMiddleware.php Line: 111any ideas
tired adding

// Page Loading event
function Page_Loading() {
	if (CurrentPageID() == "custom") CurrentPage()->CheckToken = FALSE;
}

Check token for form post is tickedthanks

Please note that CheckToken property that belongs to the Table/Page class does not exist any more in v2021. That code only works for v2020.

Ok thanks, do you know how i can ulload a file within a custom page
Cheers

You may refer to the generated code in views/{Tablename}Add.php. For example, from the demo project, you may see this code from views/CarsAdd.php file:

<form name="fcarsadd" id="fcarsadd" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl() ?>" method="post">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>
...
</form>

You don’t have to copy paste all the code, just copy the code that related to token. That code should give you the idea how to implement token for your form in Custom Files.

Many thanks for pointing me in the correct location

Hi
Has anything change in V2022 as getting
400 Bad Request Type: Slim\Exception\HttpBadRequestException Code: 400 Message: Invalid post request File:
when i try and submit a form with a file attached. same code work fine in V2021

<form enctype="multipart/form-data" id="proposal_form" method="post" class="form-horizontal">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>

thanks

You should remove enctype=“multipart/form-data”.

thanks, but this still give me
DEBUG: 400 Bad Request Type: Slim\Exception\HttpBadRequestException Code: 400 Message: Invalid post request File:

Make sure you have included action attribute in your `<form … >’ tag.For your references, you may see the generated code inside views subfolder.

all sorted many thanks

This is alife saver !. Thank you