When a user accesses my page they are taken to a home screen (which currently has a title and 1 button). The one button is start game which should redirect to a view that has the game board on it. How do I send that information from the button to the controller to access a new view.
This is the button that is in my view (the button should send the information to function click() )
<form id="start" action="index.php/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>
Now in the controller index.php
function click()
{
$action = $_POST['submit'];
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
I have it loading the welcome_message just for sakes to learn how to redirect. (My group hasn't fully build the game board page)
try,
function click()
{
$action = $_POST['start'];
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
There are couple of things you need to change.
1. Try to use another name instead of "index.php"
for controller. For example "test.php"
. I think index.php is not allowed for controller name.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
public function click()
{
$action = $this->input->post('start'); // $_POST['start']; also works.
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
}
2.Change the value of action
as follows in your view.
<form id="start" action="test/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>
This should work. Thanks.