admin管理员组

文章数量:1200964

i have a form submission in my view page as follow:

<form class="propertyForm" method="POST" action="<?= url_to('props.estimate.price'); ?>">

        <label for="roomCount" style="display: block; margin: 5px 0;">Room Count:</label>
        <input type="number" name="roomCount" id="roomCount" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="size" style="display: block; margin: 5px 0;">Size (sq ft):</label>
        <input type="number" name="size" id="size" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="floor" style="display: block; margin: 5px 0;">Floor:</label>
        <input type="number" name="floor" id="floor" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="districtClass" style="display: block; margin: 5px 0;">District Class:</label>
        <input type="text" name="districtClass" id="districtClass" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="buildingAge" style="display: block; margin: 5px 0;">Building Age Category:</label>
        <input type="number" name="buildingAge" id="buildingAge" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <input type="submit" value="Calculate" style="width: 100%; padding: 10px;">
    </form> 

and here is my controller method:

   public function estimatePropPrice() {
        // Log all POST data
        $postData = $this->request->getPost();
        log_message('info', 'Received POST data: ' . print_r($postData, true));
    
        // Get values from input
        $roomCount = $this->request->getPost('roomCount');
        $size = $this->request->getPost('size');
        $floor = $this->request->getPost('floor');
        $districtClass = $this->request->getPost('districtClass');
        $buildingAge = $this->request->getPost('buildingAge');
    
        // Create a new point from the input data
        $testPoint = [
            'RoomCount' => $roomCount, // Changed to match the database column name
            'Size' => $size,
            'Floor' => $floor,
            'District_Class' => $districtClass,
            'BuildingAge' => $buildingAge, // Changed to match the database column name
        ];
..... 

but in controller i cant get the posted data; while i add the requirements as follow to routs:

    $routes->get('prop-estimate', 'Properties\PropertiesController::estimatePropPrice',['as'=>'estimate.prop.price']);
    $routes->post('estimatePropPrice', 'Properties\PropertiesController::estimatePropPrice',['as'=>'props.estimate.price']);

but i think i miss something;

(i use local host and zampp)

can anyone help to disolve? thanks in advance.

solve my code misunderstood and make my code work

本文标签: phpretrive form data in controller method in codeigniter 4 and routs requirementsStack Overflow