Probably something obvious that I fail to see where it goes wrong. Perhaps its the logic I misunderstand. I searched quite a lot and everything I found only dealt with navigation problems for selecting the proper tabs.
I have a rather large site developed using PHP on platform codeigniter v2.2.3. It uses FORMS, FORM validation and ocassionally some jQuery (mainly for visualisation). So I know how the Model, Controller, View system works even as Form validation and display of errors, refilling forms etc.
The problem: I have a backend where some controllers provide me data on several topics and allow me to make changes using simple PHP/CI forms. I want to integrate these various controllers that are now started from a switchboard/one page into one page with TABS. So I can use tabbed views. Mainly one tab linked to one controller.
I can display the tabs, fill it with data from a controller/view. I can also show a form on a tab when selected. However: when I submit the form, my view breaks out of the TABBED view. The same when errors are generated. I don't want to recode all logic of validation over to jquery. The site is simply too large.
Question: I am looking how to properly display the reopened form when there were form validation errors...
screendump of tabs with form
Below the "logic". The complete code (an isolated username, email example) can be found at my public bitbucket repo: https://bitbucket.org/ALchEmiXt/ci-tab-test
Building the tabs:
Initial controller testtab:
<?php
class Testtab extends CI_Controller {
function index()
{
$this->data['welcome'] = 'Welcome tester!';
$this->load->view( 'testtab_view', $this->data );
}
}
?>
Initial view testtab_view: (footer and header load all default generic jquery, bootstrap logic)
<?php $this->load->view('header_testform'); ?>
<ul class="nav nav-tabs" id="uvpbTabs">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#form1" data-tab-url="testform">formtesting</a></li>
<li><a data-toggle="tab" href="#stats">Stats</a></li>
<li><a data-toggle="tab" href="#admin">Admin</a></li>
</ul>
<!-- The data and views come here -->
<div class="tab-content" id="all-tabs">
<div id="home" class="tab-pane fade in active"><h3><?php echo $welcome ?></h3></div>
<div id="form1" class="tab-pane fade"></div>
<div id="stats" class="tab-pane fade"><h3>Stats of the pages</h3></div>
<div id="admin" class="tab-pane fade"><h3>Admin stuff</h3></div>
</div>
<?php $this->load->view('footer_testform'); ?>
The form
testform controller:
<?php
class Testform extends CI_Controller {
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run() == FALSE) {
$this->load->view('testtabform_view');
} else {
$this->load->view('testform_succes');
}
}
}
?>
testtabform_view
<div id="formcontainer">
<?php echo validation_errors(); ?>
<?php echo form_open('testform'); ?>
<h3>TestTabForm_view</h3>
<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</div>
if ($this->form_validation->run() == FALSE)
}
// $this->load->view('testtabform_view');
$this->session->set_flashdata('validation_errors', validation_errors());
redirect('testtab');
}
else
{
$this->load->view('testform_succes');
}
Then control $this->session->flashdata('validation_errors'); checking if those are set.
Related
I am trying to a create a View which provides a summary table of various site members profiles - then each summary has a button, that once clicked, takes the user to that member's full profile. I can get the summary page to work properly, but I cant get the second part -where the button takes the user to the members full profile to work.
Here is my controller:
public function network_barre()
{
$this->load->model("Profiles_model");
$style ='barre';
$profilesubdata["fetch_data"] = $this->Profiles_model->fetch_data($style);
$this->load->view('templates/header');
$this->load->view('pages/page-network_barre', $profilesubdata);
$this->load->view('templates/footer');
Here is my Model "Profiles Model"
function fetch_data($style)
{
$this->db->select("username, email, style, about");
$this->db->from("profiles");
$this->db->where('style', $style);
$query = $this->db->get();
return $query;
}
Here is the view
<div class="container">
<div class="row d-flex justify-content-center card-top">
<?php
if($fetch_data->num_rows()>0)
{
foreach ($fetch_data->result() as $row)
{
?>
<div class="col-lg-4 col-md-6">
<div class="card card-warning wow zoomInUp mb-4 animation-delay-5">
<div class="withripple zoom-img">
<img src="<?=base_url();?>assets/img/demo/avatar4.jpg" class="img-fluid">
</div>
<div class="card-body">
<span class="badge badge-warning pull-right"><?php echo $row->style; ?></span>
<h3 class="color-warning"><?php echo $row->username; ?></h3>
<p><?php $string=character_limiter($row->about, 255, '…(More in Profile)') ; echo $string?></p>
<div class="row">
<div class="col text-center">
<!-- BUTTON -->
<form method="POST" action="<?php echo base_url(); ?>public_area/gotopublicprofile/<?php echo $row->email; ?>">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
<button type="submit" class="btn btn-raised btn-sm btn-warning" name="submit" value="submit"><i class="zmdi zmdi-account"></i>Profile</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php //this tag close out php tags above
}
}
?>
</div>
</div>
here is Controller gotopublicprofile
function gotopublicprofile()
{
$this->load->model("profiles_model");
$email = '$this->uri->segment(3)';
$profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata($email);
$this->load->view('templates/header');
$this->load->view('pages/page-profilepublic', $profiledata);
$this->load->view('templates/footer');
}
And here is the fetch_profiledata function in the Model:
function fetch_profiledata($email)
{
$this->db->where('email', $email);
$query = $this->db->get("profiles");
return $query;
}
I always get these error messages:
Undefined property: Public_area::$Profiles_model
AND
Call to a member function fetch_profiledata() on null
I am sure I am just missing something simple, as lots of websites use this approach.
Thanks in advance!
So I figured it out..it was a combination of little things:
First
$email = '$this->uri->segment(3)';
became
$email = $this->uri->segment(3);
Thanks #kirb! and
function gotopublicprofile()
{
$this->load->model("profiles_model");
became
function gotopublicprofile()
{
$this->load->model("Profiles_model");
Thanks #Atal Prateek!
I'm using CodeIgniter form_validation and
Everything works good except the original notification still appears in the top right.
Can anybody advise me how to delete the original notification?
I've inserted the PHP code into to view page.
<?php echo form_error('uname'); ?>
The form_error message appears the way I want but the original error message still appears in the top right, and I don't know how to delete that.
EDIT 01/08/19
Below is edited coding I've taken from the CI UserGuide.
Controller
<?php
class Form extends CI_Controller
{
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required', array('required' => 'You must provide a %s.'));
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
View
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
If the above is loaded the result will be the Username Text Box in the top left corner, and the Password Text Box below it.
If the Submit button is clicked without any content in the text boxes the following notifications appear in the top left corner and above the Text Boxes.
You must provide a Username.
You must provide a Password.
However, if I change the view page to the following, the same notifications STILL APPEAR IN THE TOP LEFT CORNER, as well as next to the Text Boxes, so in effect each notification appears twice.
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<?php echo form_error('username'); ?>
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<?php echo form_error('password'); ?>
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
It is the notifications that still appear in the top left corner, that I want to delete.
I can't find any coding that positions the notifications so I guess that comes from somewhere within the CI system.
I can position the form_error notifications by using css coding.
I found the problem.
<?php echo form_error('username'); ?> // When this is inserted.
<?php echo validation_errors(); ?> //This must be deleted.
Or put another way the coding above provides the notifications at the top right.
We build a custom bundle follow with this instructor https://blog.sulu.io/how-to-develop-a-bundle-in-the-sulu-admin-1
We need to know how to pass data from a database to render radio input choices or dropdown select.
We try to create an add/edit form and in the form, we have a radio and dropdown we made with hardcore in HTML file in Vendor/TransportationBundle/Resources/public/js/components/transportation/form/form.html
The code is
<div class="grid-row">
<label for="transportation-transportationType"><%= translations.transportationType %></label>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-1" type="radio"
class="form-element content-type" value="1" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.private_shuttle %></span>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-2" type="radio"
class="form-element content-type" value="2" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.shared_shuttle %></span>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-3" type="radio"
class="form-element content-type" value="3" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.airplane %></span>
</div>
Is this have a way to change those radio to fetch the data from an array or a way to fetch the data from some controller action? or Have another way to use twig file with twig feature instead of html file?
Please provide a solution for us? Thank you
Sorry for my English.
You can e.g. check this Controller from the core. You can get data from wherever you want in the controller and pass it to the template:
<?php
class AcmeController {
public function testAction() {
$data = /* Get data somehow */;
return $this->render('template', ['data' => $data]);
}
}
Then you can access the data using the data twig variable in the rendered template.
I'm a beginner in the AngularJs and MongoDb world (i started learning today!!)
Actually i'm trying to do something very basic : Display a list of record, with an add button and a edit link with each record.
I'm using this lib https://github.com/pkozlowski-opensource/angularjs-mongolab to connect to mongoweb.
Actually my data is displayed, when i try to add a record it works, but the problem is when i try to display the edit form!
Here is my index.html file, in which i display the data with a form to add a record and with the edit links :
<div ng-controller="AppCtrl">
<ul>
<li ng-repeat="team in teams">
{{team.name}}
{{team.description}}
edit
</li>
</ul>
<form ng-submit="addTeam()">
<input type="text" ng-model="team.name" size="30" placeholder="add new team here">
<input type="text" ng-model="team.description" size="30" placeholder="add new team here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
And here is my edit.html code, which displays an edit form :
<div ng-controller="EditCtrl">
<form ng-submit="editTeam()">
<input type="text" name="name" ng-model="team.name" size="30" placeholder="edit team here">
<input type="text" name="description" ng-model="team.description" size="30" placeholder="edit team here">
<input class="btn-primary" type="submit" value="validate edit">
</form>
</div>
And finally my js code:
var app = angular.module('app', ['mongolabResource']);
app.constant('API_KEY', '____________________________');
app.constant('DB_NAME', 'groups');
app.factory('Teams', function ($mongolabResource) {
return $mongolabResource('teams');
});
app.controller('AppCtrl', function ($scope, Teams) {
$scope.teams = Teams.query();
$scope.addTeam = function() {
varteam = {
name: $scope.team.name,
description: $scope.team.description
};
$scope.teams.push(varteam);
Teams.save($scope.team);
$scope.team.name = '';
$scope.team.description = '';
};
});
app.controller('EditCtrl', function ($scope, Teams) {
//????????
});
My AppCtrl works perfecty, it displays the data w add records perfectly.
Now i want to add the js code for the edit, but i don't even know form where to start ? how do i a get the id parameter in the url ? how do i tell the view to fill out the form fields from the values from the database ? And finally how do i update the databse.
I know that i asked a lot of question but i'm really lost! thank you
There are of course many possible solutions.
One solution is to use angularjs routing. See http://docs.angularjs.org/tutorial/step_07 for a tutorial.
Basically replace your ul list with something like:
<ul>
<li ng-repeat="team in teams">
{{team.name}}
{{team.description}}
edit
</li>
</ul>
Then you can create a route that responde to your url:
yourApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/teams', {
templateUrl: 'partials/team-list.html',
controller: 'TeamListCtrl'
}).
when('/teams/:teamId', {
templateUrl: 'partials/team-detail.html',
controller: 'TeamDetailCtrl'
}).
otherwise({
redirectTo: '/teams'
});
}]);
In this way from the detail controller (that will replace your EditCtrl) you can access the id parameter using: $routeParams.teamId
Anyway I suggest to study well all the tutorials for a better overview.
i am new to zend i have coded up to some extent but dont know further how to decorate my form using decorators etc
this is my old HTML
<div class="col_6 pre_3 padding_top_60" style="padding-top:0">
<div class="widget clearfix">
<div class="widget_inside">
<p class="margin_bottom_15">Kindly enter Username and Password.</p>
<span><?= $this->error;?></span>
<form method='post' action='<?php echo $this->url(array(), 'login') ?>' onsubmit="return validateForm();">
<div class="form">
<div class="clearfix" id="div_username">
<label class="lable-2">Username</label>
<div class="input">
<input type="text" class="xlarge" name="username" id="username" value="<?php echo $this->form['username'] ?>"/>
<span id="error_message_username"></span>
</div>
</div>
<div class="clearfix" id="div_password">
<label class="lable-2">Password</label>
<div class="input">
<input type="password" class="xlarge" name="password" id="password" value="<?php echo $this->form['password'] ?>"/>
<span id="error_message_Password"></span>
</div>
</div>
<div class="clearfix">
<label></label>
<div class="input">
<input type="checkbox" name="remember" value="1" <?php echo ($this->form['remember'] == 1)?'checked="checked"':'' ?>/></span> Stay signed in
<span style="margin-left:10px">Forgot User ID or Password </span>
</div>
</div>
<div class="clearfix">
<label></label>
<div class="input">
<input type="submit" value="Login" class="medium button blue blue-1"/>
</div> </div>
</div>
</form>
</div>
</div>
This is my Form
<?php
class Application_Form_Loginform extends Zend_Form{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$this->setMethod('post');
$this->addElement('text','username',array(
'label' => 'UserName :',
'required' => true,
'filters' => array('StringTrim')
));
$this->addElement('password','password',array(
'label' => 'Password',
'required' => 'true',
'filters' => array('StringTrim')
));
$this->addElement('submit','submit',array(
'ignore'=>'true',
'label'=>'Login'
));
}
}
Question is How can i make my form made with php equal to the above HTML ??
Zend Form is a pain to use, especially decorators.
You should use the View Script decorator instead.
See here: http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript
Aside from Zend Form decorators having a high learning curve, it mixes view code with logic and validation code.
This is not a good thing, especially if you have frontend developers styling and working with the forms.
It also makes prototyping the look of the forms difficult since you have to keep adjusting the decorator code.
With that said, Zend Form does a good job of making validation relatively painless. But one other gripe with it is that I don't think it fits well model validation.
I agree that decorators are complex, but they save a GREAT DEAL of time, when you know how to use them. We use them for our admin panel. We recently changed it from table layout to few fieldsets and divs and it took only few hours to change 70+ forms.
Your validators should be something like:
Form:
form,
htmlTag (div, class=form)
formElements
Elements:
viewHelper
error, placement => append
htmlTag (div, class input)
Label, placement => prepend
htmlTag (div, class=clearfix)
just keep in mind you need to set different keys for each htmlTag decorator, or else they would be overwritten. Like this:
....
array('inputHtmlTag' => 'htmlTag, array('tag' => 'div', 'class' => 'input'),
....
To see how I deal with complex Twitter Bootstrap decorators see https://github.com/tomasfejfar/Zend-Form-Bootstrap/blob/master/library/Bootstrap/Form.php There you can find clues how to implement your own markup.