Welcome Guest, Not a member yet? Register   Sign In
form POST not working
#1

Hi,

First post here so please bear with me. I've had a search and this thread https://forum.codeigniter.com/showthread.php?tid=77603 is pretty close to what I'm seeing.

I'm running MAMP on a brand new Mac with OSX 14.2 and I'm trying to port a (very, very) old CI3 based site to CI4. I've a feeling it's over ten years since I wrote it and since it "worked" I rarely touched it except when updating the underlying database and needed to handle another field/database column. The site will never go public, it's simply so I can manage a club's membership.

The problem I'm facing is with passing control from a form to a handler, I've not even got to the point . I get the following message:



Quote:Firefox can’t establish a connection to the server at localhost:8080.


This happens regardless of whether "index.php" is in the URL or not.

The form:

Code:
<form action="http://localhost:8080/public/bgrapp/registration/add" method="post" accept-charset="utf-8">
<fieldset>
<legend>Complete Data</legend>
<input type="text" name="complete" value="" id="complete" placeholder="Paste the comma separated data here">
</fieldset><input type="submit" name="add" value="Add Contender" id="add">
</form>
The associated route in Config/Routes.php
PHP Code:
$routes->post('registration/add''Registration::add'); 
The controller registration.php

PHP Code:
class Registration extends BaseController{

    /**
 * index
 * The default method for this controller. It simply displays the
 * data entry form for runner details.
 *
 * @access public
 * @param None
 * @return Nothing
 */
    public function index(): string{
 
$data['title'] = "Register The Contender";

        return view('header'$data)
            view('menu'$data)
            view('registration'$data)
            view('footer'$data);
 }

  /**
 * add
 * This is the form handler. It takes the values of the 
 * form via the input class and adds them to the session data
 *
 * @access public
 * @param None
 * @return Nothing
 */
    public function add() {
        $dest site_url('registration');

        $c = new Contender_model();

        $data $this->input->post(NULLTRUE);

        $c->add_contender($data);

 
redirect($dest);
 }



I'm aware that the retrieval of POST data has changed in the intervening years but I can sort that out when I get to it.

I'm obviously missing something but obviously I don't know what!

TIA
Reply
#2

SEE: The part Add News::create() to Create a News Item.

CodeIgniter 4 User Guide - Build Your First Application Create News Items
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

The port number is correct?
localhost:8080

Why your URL contains `public`? Where did you install CodeIgniter?
http://localhost:8080/public/bgrapp/registration/add

I recommend you read the User Guide.
https://codeigniter4.github.io/CodeIgnit...ith-apache
Reply
#4

(This post was last modified: 03-03-2024, 01:57 AM by bobw.)

I installed CodeIgniter at /Applications/MAMP/htdocs/bgrapp using manual installation as per https://www.codeigniter.com/user_guide/i...anual.html (I tried following the Composer instructions but couldn't get my head around them - my fault not those of Composer) In Config/App.php I have

PHP Code:
public string $baseURL 'http://localhost:8080/bgrapp/'

One thing I didn't change was adding "127.0.0.1 bgrapp" to /etc/hosts, it's read-only on my system.

After I made the initial post I noted that the port number changed from localhost:8888 (the MAMP Apache default) to localhost:8080 but because I'm a new member I couldn't edit the post until a moderator had cleared it. By the time I realised it was late and I needed some sleep.
I added this to hpptd-vhosts.conf

Code:
<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/bgrapp"
    ServerName  bgrapp
    ErrorLog    "logs/myproject-error_log"
    CustomLog    "logs/myproject-access_log" common

    <Directory "/Applications/MAMP/htdocs/bgrapp">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


@InsiteFX I actually used form_open('registration/add'); which is how I'd done it in CI3, the form code posted is what was generated. Are you suggesting I ignore the form_xxx() functions and write out the form myself?
Reply
#5

Your document root should be "/Applications/MAMP/htdocs/bgrapp/public".
See https://codeigniter4.github.io/CodeIgnit...irtualhost
Reply
#6

(This post was last modified: 03-03-2024, 02:43 AM by bobw.)

OK. Made that change and restarted Apache.

Now I when I go to the home page "http://localhost:8888/bgrapp/" I just get a directory listing. Append "public" to the URI and the home page appears.

As a test I tried changing the port number for Apache in MAMP to 8080 and it now works. Well, there are other errors but mostly migration issues. The URI still contains "public" but since I'm the only person likely to use this and I can just bookmark the site I'm not overly worried unless it's going to cause problems further down the line.
Reply
Reply
#8

DocumentRoot "/Applications/MAMP/htdocs/bgrapp/public"
Reply
#9

You can add it to your hosts file you need to use notepad as an elevated Administrator
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB