I have a two controller function, Index function and generateReport function, when I click the export button it should direct me to this URI index.php/schoolScoreCardReport/generateReport, the problem is it directs me to this URI index.php/generateReport, i dont know why, here is my code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class schoolScoreCardReport extends PG_Controller {
public function __construct(){
parent::__construct();
}
public function index(){
if(isset($_POST['Export'])){
$this->generateReport();
}
$this->layout->view('report/index');
}
public function generatePOMEDetailReport(){
$this->layout->view('test/index');
}
}
Pls help me thankyou here is my html view for index function
<table>
<?php echo form_open('schoolScoreCardReport'); ?>
<tr><td>
<label>Region:</label>
<select name="region_name" style="width:150px">
<option value = "1">a</option>
</select>
</td></tr>
<tr><td>
<input type="submit" id="btn_export" value="Export" name="Export">
</td></tr>
<?php echo form_close(); ?>
</table>
Unless you have some routes going on to affect the requests, I believe the parameter sent to form_open() should be as follows...
<?php echo form_open('schoolScoreCardReport/generatePOMEDetailReport'); ?>
As generatePOMEDetailReport is the only function shown in your controller code above other than the index function.
If you really want it to call the index function so the IF $post check is done, try 'schoolScoreCardReport/index' for the parameter.
I think there is a one-to-one relationship between a URL string and its corresponding controller class/method in codeigniter. The segments in a URI normally follow this
example.com/class/function/id/
or you see this link :https://www.codeigniter.com/userguide3/general/routing.html
in form_open u need to follow this
<?php echo form_open('ControllerName/FunctionName'); ?>
in your case it is
<table>
<?php echo form_open('schoolScoreCardReport/generatePOMEDetailReport'); ?>
<tr><td>
<label>Region:</label>
<select name="region_name" style="width:150px">
<option value = "1">a</option>
</select>
</td></tr>
<tr><td>
<input type="submit" id="btn_export" value="Export" name="Export">
</td></tr>
<?php echo form_close(); ?>
</table>
Related
I’m trying to make a simple example in Phalcon PHP framework, so i have a view which contain two fields name and email and a submit button. When i click in this button a function of a controller is called to store the name and the email in the DB. This action goes well the problem is I’m trying to display a message after the action ends but i still have the view that contain the form (name, email). Here's my code.
My checkout controller.
<?php
class CheckoutController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
}
public function registerAction()
{
$email = new Emails();
//Stocker l'email et vérifier les erreurs
$success = $email->save($this->request->getPost(), array('name', 'email'));
if ($success) {
echo "Thanks for shopping with us!";
} else {
echo "Sorry:";
foreach ($user->getMessages() as $message) {
echo $message->getMessage(), "<br/>";
}
}
}
}
The view
<!DOCTYPE html>
<html>
<head>
<title>Yuzu Test</title>
</head>
<body>
<?php use Phalcon\Tag; ?>
<h2>Checkout</h2>
<?php echo Tag::form("checkout/register"); ?>
<td>
<tr>
<label for="name">Name: </label>
<?php echo Tag::textField("name") ?>
</tr>
</td>
<td>
<tr>
<label for="name">E-Mail: </label>
<?php echo Tag::textField("email") ?>
</tr>
</td>
<td>
<tr>
<?php echo Tag::submitButton("Checkout") ?>
</tr>
</td>
</form>
</body>
</html>
You can use Flash Messages, so you don't have to break the application flow.
Regards
echo() during controller code won't (shouldn't) work unless you turn off your views, because its buffered and cleared after dispatching.
If you want to be sure it's happening this way, just add die() at the end of registerAction() method.
If you create separate view for registerAction(), you can use there variables you declare with $this->view->message = ... or $this->view->setVar('message', ...) in controller method. Than, in view file you can reuse them by <?php echo $this->view->message; ?> or <? echo $message; ?>.
I think you have to write following line in the end of your controller function registerAction
$this->view->disable();
I'm using the function below, getAllMifs() which uses PDO::FETCH_OBJ to return a stdClass object called $mifs.
Here is my model:
public function getAllMifs()
{
$sql = "SELECT id, color, L, A, B FROM pantonePlus2010";
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll();
}
Here is my controller:
Class Mifs extends Controller
{
public function index()
{
echo 'Message from Controller: You are in the Controller: Mifs, using the method index().';
$mifs_model = $this->loadModel('MifsModel');
$mifs = $mifs_model->getAllMifs();
// load views. within the views we can echo out $mifs and $amount_of_mifs easily
require 'application/views/_templates/header.php';
require 'application/views/mifs/index.php';
require 'application/views/_templates/footer.php';
}
Here is my View file:
<div>
<?php foreach ($mifs as $mif) { ?>
<form name="mifselect" action="<?php echo URL . 'mifs/downloadmif/' . $mif->id; ?>">
<select name="mifselect">
<option value="<?= $mif->id ?>"><?= $mif->color ?></option>
</select>
<input type="submit" value="Submit">
</form>
<?php } ?>
</div>
The problem I can't figure out is how to get the result into one drop down menu. I tried to attach a screenshot that shows the stdClass array and five drop down list the foreach ($mifs as $mif) creates but this is my first post and Stackoverflow.com requires me to have 10 reputations to post images...
I have tried this with PDO_ASSOC as well as PDO_OBJ but I still get the five drop down lists.
This must be the problem: id ?>">color ?> code but I can't find the correction to get just the one drop down list.
Any help is appreciated, thanks in advance!
please place options only inside loop
<div>
<form name="mifselect" action="<?php echo URL . 'mifs/downloadmif/' . $mif->id; ?>">
<select name="mifselect">
<?php foreach ($mifs as $mif) { ?>
<option value="<?= $mif->id ?>"><?= $mif->color ?></option>
<?php } ?>
</select>
<input type="submit" value="Submit">
</form>
</div>
I am new to code igniter. I've created a form but it is not display properly.
When I put
<?php echo form_open('sms'); ?> instead of <form action="">tag
here in my form and controller, I can't understand why it is not displayed.
<?php echo form_open('sms'); ?>
<p>
<label><strong>Username</strong>
<input type="text" name="textfield" class="inputText" id="textfield" />
</label>
</p>
<p>
<label><strong>Password</strong>
<input type="password" name="textfield2" class="inputText" id="textfield2" />
</label>
</p>
<input type="submit" value="Authentification" name="auth" />
<label>
<input type="checkbox" name="checkbox" id="checkbox" />
Remember me</label>
</form>
and my controller is
<?php
class sms extends CI_Controller{
function school(){
$this->load->view('school/index.php');
if($this->input->post('auth',TRUE)){
$this->load->view('school/dashboard.php');
}
else{
$this->load->view('school/index.php');
}
}
}
?>
If this is your entire script for the most part, it looks like you need to load the helper first from the CodeIgniter Form Helper Page.
If you don't have this line, try adding it before the form_open() function:
<?php $this->load->helper('form'); ?>
While I have used CodeIgniter, it's been a while. Let me know if that changes the result.
Edit: Since you've chosen my answer I'll include this one, credits go out to devo:
You could change </form> to: <?php echo form_close(); ?>. There are pros and cons for this method though, and without using arguments you might be better off sticking with </form>.
I'll explain further:
<div class="registration">
<div class="form-box">
<?php $this->load->helper( 'form' ); ?>
<?php $end = '</div></div>'; ?>
<?php echo form_open( 'register' ); ?>
<!-- Form Inputs Here -->
<?php echo form_close( $end ); ?>
<!-- Echos '</form></div></div>' -->
So for closing the form without arguments, the </form> tag works best, both by performance and simplicity. The example used above is a rather simplistic view of what you can do with it, since what I wrote is not very efficient either.
However, this is still php we're talking about, so perhaps the craftier among us could put it to better use.
End Edit
Have you loaded the form helper? You can use $this->load->helper('form'); in your controller action, her inside function school(). You can then use form helper in the view pages.
Load form helper,
$this->load->helper('form');
And use,
echo form_close()
Instead of,
</form>
First in your Controller put in:
$this->load->helper('form');
And Change </form> to :
<?php echo form_close(); ?>
below is my 'mainview.php' view. from here iam attempting to submit and just open the next view which is called 'carerview.php'.
<form action="<?php echo base_url()?>login" method="post">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="" name="" placeholder="your#email.com"></br></br>
<div class="input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" id="" name="" placeholder="Password"></br></br>
<button type="submit" class="btn btn-primary"><i class="icon-user icon-white"></i>Sign in</button>
</div>
</div>
</form>
Iam trying to submit this is giving me issues.The Index page loads which contains the above view. but when i submit . i get requested URL not found on this server
. then if i use the full url action="application/controllers/user/login" i get a forbidden, dont have permission to access it.
my method in my controller class is just to load the next view on submit so i dont think there is an issue there . below is the controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index()
{
if(!$this->isLoggedIn())
{
$this->load->view('mainview');
}
else
{
//do something
}
}
public function login()
{
$this->load->view('carerview');
}
public function isLoggedIn()
{
return false;
}
}
any help would be appreciated thanks.
if you didn't remove index.php from your URL and didn't set anything to base_url in configuration,try this
<?php echo base_url();?>index.php/user/login
localhost/your_app_folder/index.php/controller/action
Your form action is base_url(), which means is the application index route.
Try using form_open() (in the form_helper), which takes care of building the correct url:
<?php echo form_open('user/login');?>
... your form here
<?php echo form_close();?> // since I didn't see a close form tag in your form
Be careful of any routes that might intercept the request.
Alternatively, you could use site_url():
<form method="POST" action="<?php echo site_url('user/login');?>">
This i'm sure is a simple overlook, but its given me quite a headache in a short time period.
Im trying to post data from this view:
<?php
if (!$this->tank_auth->is_logged_in())
{
echo "<a href='index.php/auth/login'>Login</a>";
} else { ?>
<form method="POST" action="create_community">
<label>Community Name: </label><input type="text" name="communityname" value="231"/><br>
<label>Description: </label><br><textarea name="communitydesc"></textarea><br>
<label>Image Location(URL): </label><input type="text" name="imageloc"/><br>
<input type="radio" name="privacy" value="public" /> public<br />
<input type="radio" name="privacy" value="private" /> private<br />
<input type="radio" name="privacy" value="business" /> business<br />
<input type='submit'/>
</form>
<?php }
?>
create controller is the following:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Create extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('tank_auth');
$this->load->library('encrypt');
$this->load->library('session');
$this->load->model('topbar_model');
$this->load->model('left_model');
$this->load->model('right_model');
/*
$this->load->model('right_model');
$this->load->model('left_model');
$this->load->model('topic_model');
*/
$this->load->helper('url');
$this->load->helper('form_helper');
$this->load->helper('form');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security');
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
}
public function index()
{
$this->load->view('create_community');
}
public function create_community()
{
$this->load->view('templates/head');
echo "testing";
print_r($this->input->post());
}
}
create_community shows "testing" but does not show the post. I've tried posting individual input contents as well, and just get nothing.
Any ideas?
The believe $this->input->get_post() is a method call, not a class variable, so you can't handle like you would $_POST[].
If you are wanting to follow traditional form processing using POST, use the standard $_POST[] assoc. array, but be aware that there might be a CSRF field that will be included, and that you will need to handle.
Also, I don't know how you are routing, but shouldn't your form action be 'create/create_community', unless you are routing past 'create' for all calls at this point.
public function create_community()
{
var_dump($this->input->post());
}