1060

Validation helper redirects back to : http://localhost/

Showing 1 to 10 of 11 comments.

Comments for “Validation helper redirects back to : http://localhost/”
 

Posted by MFahad on Thursday 9th May 2024 at 07:26 GMT

Hi, I have a problem that when I run this
$result = $this->validation_helper->run();
It redircets from http://localhost/demo/attendance to this url: http://localhost/demo/.
which is undesired.

MFahad

User Level: Guest

Date Joined: 30/07/2022

Posted by DaFa on Thursday 9th May 2024 at 08:48 GMT

Need more info... What are you validating? What's in the form? What version of Trongate? Code example...
Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by MFahad on Thursday 9th May 2024 at 11:09 GMT

* Trongate *
* Version: 1.3.3049

form part:
<form method="post" action="<?= $form_location ?>" >
    <?=validation_errors() ?>
        <div class="mb-4">
            <label for="inputContact" class="block text-gray-700 font-semibold mb-2">Email or Phone Number</label>
            <input type="text" id="inputContact" name="inputContact" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500" placeholder="Enter email or phone number" autofocus>
        </div>
        <button type="submit" class="w-full bg-blue-500 text-white py-2 px-4 rounded-md font-semibold hover:bg-blue-600 transition duration-300">Mark Attendance</button>
    </form>



controller:

<?php
class Attendance extends Trongate {

	/**
	 * Renders the (default) 'welcome' webpage for public access.
	 *
	 * @return void
	 */
	function index(): void {
        $first_segment = segment(1);
        $data['form_location'] = str_replace($first_segment, $first_segment.'/store', current_url());
		$data['view_module'] = 'attendance'; // Indicates the module where the view file exists.
		$data['view_file'] = 'attendance'; // Specifies the base name of the target PHP view file.
		$this->template('public', $data); // Loads the 'welcome' view file within the public template.
	}
    function store(){
        $this->validation_helper->set_rules('email', 'email', 'required');
        // Run the validation tests
        $result = $this->validation_helper->run();
      }
      
}

This comment was edited by MFahad on Thursday 9th May 2024 at 11:15 GMT

MFahad

User Level: Guest

Date Joined: 30/07/2022

Posted by MFahad on Friday 10th May 2024 at 12:24 GMT

in the latest trongate it says: This page isn’t workinglocalhost is currently unable to handle this request.
HTTP ERROR 500

MFahad

User Level: Guest

Date Joined: 30/07/2022

Posted by DaFa on Saturday 11th May 2024 at 01:52 GMT

I'll try to get to your request over the weekend. I am busy with a few things at the moment. Yes, I have seen that server error too, and will let DC know or try to solve it if I get the time.
Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by DaFa on Saturday 11th May 2024 at 08:59 GMT

OK, a few things are going on here
- firstly, you need to ensure the validation rules match the form element "inputContact" so the corresponding rules should be:
$this->validation_helper->set_rules('inputContact', 'Email or Phone', 'required');

- secondly, the reason you are being redirected is because of CSRF.

Add
<?= form_close() ?>
to your form.

This comment was edited by DaFa on Wednesday 15th May 2024 at 07:00 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by MFahad on Monday 13th May 2024 at 05:38 GMT

still same with the above proposed methods.

MFahad

User Level: Guest

Date Joined: 30/07/2022

Posted by Davcon on Wednesday 15th May 2024 at 00:37 GMT

I think the problem could be your form location.
Founding Member

Davcon

User Level: Founding Member

Date Joined: 3/11/2018

Posted by DaFa on Wednesday 15th May 2024 at 07:11 GMT

That's fine DC - it works fine for me - here is the code I created based on the above:
<?PHP
// modules\attendance\controllers\Attendance.php
class Attendance extends Trongate {
    function index(): void {
        $first_segment = segment(1);
        $data['form_location'] = str_replace($first_segment, $first_segment . '/store', current_url());
        $data['view_module'] = 'attendance';
        $data['view_file'] = 'attendance';
        $this->template('public', $data);
    }
    function store() {

        $this->validation_helper->set_rules('inputContact', 'Email or Phone', 'required');
        // Run the validation tests
        $result = $this->validation_helper->run();

        if ($result == true) {
            echo post('inputContact', true) . '
';
            echo "Well done!";
        } else {
            redirect('attendance');
        }
    }
}

<!-- modules\attendance\views\attendance.php -->
<h1>Help bar post by <span><i>MFahad</i></span></h1>
<h2>Validation helper redirects back to : http://localhost/</h2>
<p><b>Posted by MFahad on Thursday 9th May 2024 at 07:26 GMT</b>
Hi, I have a problem that when I run this
    $result = $this->validation_helper->run();
    It redircets from http://localhost/demo/attendance to this url: http://localhost/demo/.
    which is undesired.</p>
<p><b>Posted by MFahad on Friday 10th May 2024 at 12:24 GMT</b>
in the latest trongate it says: This page isn’t workinglocalhost is currently unable to handle this request.
    HTTP ERROR 500</p>
<hr>
<div class="container-xxs">
    <?= form_open($form_location) ?>
    <?= validation_errors() ?>
    <div class="mb-4">
        <label for="inputContact" class="block text-gray-700 font-semibold mb-2">Email or Phone Number</label>
        <input type="text" id="inputContact" name="inputContact" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500" placeholder="Enter email or phone number" autofocus>
    </div>
    <button type="submit" class="w-full bg-blue-500 text-white py-2 px-4 rounded-md font-semibold hover:bg-blue-600 transition duration-300">Mark Attendance</button>
    <?= form_close() ?>
</div>

The PHP 500 error you posted on 9th May is something completely different to the first issue you were seeing...

This comment was edited by DaFa on Wednesday 15th May 2024 at 07:16 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by MFahad on Thursday 16th May 2024 at 06:53 GMT

redirecting back to the url:
http://localhost/<app_name>

was in the older trongate version. when I download latest trongate app builder, then it says:
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500

This comment was edited by MFahad on Thursday 16th May 2024 at 06:59 GMT

MFahad

User Level: Guest

Date Joined: 30/07/2022

×