I have created a custom component with form to update prices of four product to be displayed on frontend.
My main controller code is here:
public function display($cachable = false, $urlparams = false) {
require_once JPATH_COMPONENT.'/helpers/calculator.php';
$view = JFactory::getApplication()->input->getCmd('view', 'pricetable');
$layout = JFactory::getApplication()->input->getCmd('layout', 'edit');
JFactory::getApplication()->input->set( 'layout', $layout );
JFactory::getApplication()->input->set('view', $view);
JFactory::getApplication()->input->set('id', 1);
parent::display($cachable, $urlparams);
return $this;
}
id is set to 1 so it loads only first row from database.
code for pricetable container is:
function __construct() {
$this->view_list = 'pricetable';
parent::__construct();
}
Now in admin backend the form is loaded as desired with the first row of data.
When I try to save the form it is redirected to administrator/index.php?option=com_calculator&view=pricetable and error is:
Error: You are not permitted to use that link to directly access that
page (#1).
my form action is:
<?php echo JRoute::_('index.php?option=com_calculator&task=pricetable.edit&id='.(int) $this->item->id); ?>
Please suggest where I am doing wrong. It is third day I'm scratching my head. :(
You can do updating actions (or calling them) inside your code whenever it is.
New instance or update new - just add one more if in code and hidden input on form. For example:
<input type="hidden" name="task" value="update" />
Related
I have a form in a tpl file:
<form action="{$link->getModuleLink('virtual_pos', 'validation', [], true)|escape:'html'}" method="post">
...
</form>
On submit I would like to get all the variables from the form and pass them to the controller 'validation'.
I don't wanna use any JS. It is a payment module for a store.
How can I do this?
I have found a solution in another thread.
When the link to the controller is created you can fill the variables that you need in the empty array parameter:
<form action="{$link->getModuleLink('virtual_pos', 'validation', ['id'=>$cart_id], true)|escape:'html'}" method="post">
Then in the controller you can get the data with the super global
$id_from_form_submit = $GET['id'];
If you know any other option please let me know.
In your module create a file controllers/front/validation.php.
There you need a class:
class virtual_posValidationModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
/* where you get the values and validate the order */
}
public function initContent()
{
parent::initContent();
/* where you set data for a last page order confirmation */
}
}
Have you created this already?
I want to create custom permalinks on CodeIgniter, actually i bought the script but the developer left that project due to some indifference. so now the problem is i have no idea how to change permalinks on that script. The main permalinks issue is when i search anything on searchbar i get this url:
domain.com/?s=xxxxx%20yyyyy
instead of that i want this url structure:
domain.com/search/xxxxxx-yyyyy/
application/config/routes.php
$route['default_controller'] = "music";
$route['404_override'] = '';
$route['search/(:any)'] = "music/index/$0/$1/$2";
$route['search/music/(:any)'] = "music/$1";
I guess what you are asking for is not possible (directly).
Assuming your form to be,
<form action="" method="GET">
<input type="text" name="s" value="" placeholder="Search music..." />
</form>
And since the method is GET the default functionality says to add the parameter in the URL as query string.
As the specifications (RFC1866, page 46; HTML 4.x section 17.13.3) state:
If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?' to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.
So, basically what you can do here is apply a hack to this. Redirect the user to the required URL when the search is applied. Here's how you can go,
Controller (controllers/music.php)
<?php
class Music extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('xyz_model');
}
public function index()
{
if($this->input->get('s'))
{
$s = $this->input->get('s');
redirect('/search/'$s);
}
$this->load->view('home.php');
}
public function search()
{
$s = $this->uri->segment(2);
/*
Now you got your search parameter.
Search in your models and display the results.
*/
$data['search_results'] = $this->xyz_model->get_search($s);
$this->load->view('search_results.php', $data);
}
}
I have a bootstrap form where after filling data its successfully get inserted to database .Now i want to show detail view of form with filled data but it taking me back to create view after submit with data added to database. i guess i have problem with site url. for better understanding hereby i am attaching my code.
my create view file code is :
<form class="form-horizontal" id="job" action="<?php echo site_url('admission/add_students')?>" method="POST" name="job">
where as controllers(admission):
function add_students() {
$this->load->model('admission_detail_model');
$data=array(
'student_id'=>'La-0002'.$this->input->post('student_id'),
'father_name'=>$this->input->post('father_name'),
'mother_name'=>$this->input->post('mother_name'),
'fname'=>$this->input->post('first_name'),
'lname'=>$this->input->post('Last_name'),
'place_of_birth'=>$this->input->post('place_birth'),
'mother_tounge'=>$this->input->post('mother_tounge'),
'd_o_b'=>$this->input->post('DOB'),
'nationality'=>$this->input->post('nationality'),
'religion'=>$this->input->post('religion'),
'sc_st_obc'=>$this->input->post('sc_st_obc'),
'caste'=>$this->input->post('caste'),
'address'=>$this->input->post('address'),
'admitting_student'=>$this->input->post('Admit_std'),
'father_edu_qual'=>$this->input->post('father_q'),
'mother_edu_qual'=>$this->input->post('mother_q'),
'annual_income'=>$this->input->post('annual_income'),
'father_occupation'=>$this->input->post('father_occupation')
);
$this->admission_detail_model->add_students($data);
$this->index();
}
Model:
class Admission_detail_model extends CI_Model {
function add_students($data) {
$this->db->insert('students',$data);
return; }
Everything working fine i just want to add detail view after submit form not another create form View. For detail view i have controller defined in my base controller(admission) :
public function detailed_admission()
{
$this->load->helper('url');
$this->load->view('Header');
$this->load->view('side_menu');
$this->load->view('admission/detailted_view');
$this->load->view('footer');
}
when i try to replace site url in create view file
"<?php echo site_url('admission/detailted_view')?>"`
it does not enter data in database redirect directly to this view without any data.
This is my first question so if i had made any mistake please avoid it.
Thankyou for helping
Check my comments in the code.
function add_students() {
$this->load->model('admission_detail_model');
$data=array(
'student_id'=>'La-0002'.$this->input->post('student_id'),
'father_name'=>$this->input->post('father_name'),
'mother_name'=>$this->input->post('mother_name'),
'fname'=>$this->input->post('first_name'),
'lname'=>$this->input->post('Last_name'),
'place_of_birth'=>$this->input->post('place_birth'),
'mother_tounge'=>$this->input->post('mother_tounge'),
'd_o_b'=>$this->input->post('DOB'),
'nationality'=>$this->input->post('nationality'),
'religion'=>$this->input->post('religion'),
'sc_st_obc'=>$this->input->post('sc_st_obc'),
'caste'=>$this->input->post('caste'),
'address'=>$this->input->post('address'),
'admitting_student'=>$this->input->post('Admit_std'),
'father_edu_qual'=>$this->input->post('father_q'),
'mother_edu_qual'=>$this->input->post('mother_q'),
'annual_income'=>$this->input->post('annual_income'),
'father_occupation'=>$this->input->post('father_occupation')
);
//To insert the record in the database
$this->admission_detail_model->add_students($data); after
//open the detail view page
// $this->index(); why did you call index function ??
$this->detailed_admission(); //call detailed function just after the form submission or you can perform redirect('admission/detailed_admission')
}
I have created a fully custom view, I want this view to only show certain fields in an editview format so I can update records. But this view is to be different from the normal editview. How do I add a custom metadata file to this view that will allow me to define the form and fields that I need? The view is tied to a custom button and currently just shows "works". This is working so far just need to understand how to define the layout.
the controller:
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CustomCasesController extends SugarController {
function action_resolve_Case() {
$this->view = 'resolve_case';
}
}
The view :
if (!defined('sugarEntry') || !sugarEntry)
die('Not A Valid Entry Point');
require_once('include/MVC/View/SugarView.php');
class CasesViewresolve_case extends SugarView {
public function CasesViewresolve_case() {
parent::SugarView();
}
function preDisplay() {
parent::preDisplay();
}
public function display() {
// include ('test.php');
echo "works";
}
}
Old, but still may help someone...
You can :
work inside the display function. Everything you do or echo here will be shown inside the main Sugar app screen (navbar, footer, etc) so it will look native.
Work directly inside the controller and echo everything out.
Build your form with the fields you want to edit and have as action a function in controller where you can use the bean->save() method for the POST results.
<form name="whatever" method="POST" action="index.php?module=Contacts&action=yourcustomaction">
ex:
`$contact = new Contact();
$contact->retrieve("{$_REQUEST['contactId']}");
//be sure to send the id in the button/link to the view
$contact->first_name =$_POST['first_name'];
$contact->last_name =$_POST['last_name'];
.....
$contact->save();`
Not very elegant but the only other option I know of is working with smarty templates which I'm not familiar with.
If anybody has a better solution, please post it.
This is a pretty basic thing but I can't figure out how to solve this "properly" with Zend Framework:
Scenario:
Page displays form 1,
Page display form 2
This is a pretty basic thing but I can't figure out how to solve this "properly" with Zend Framework:
Scenario:
Page displays form 1,
Page displays form 2
class FooController extends Zend_Controller_Action {
...
public function form1Action(){
if ($this->getRequest()->isPost()) {
// save data from form1 in database
$this->_forward('form2');
}
// display form1
}
public function form2Action(){
if ($this->getRequest()->isPost()) {
// save data from form2 in database
$this->_forward('somewherelese');
}
// display form2
}
}
When the user posts form1, first the if-condition in form1Action is executed (which is what I want), but also the if-condition in form2Action.
What would be toe proper way to "unset $this->getRequest()->isPost()"?
Note: the forms are build "by hand" (not using Zend Form)
You have three options:
Use _redirect instead of _forward. Forward redirects under the same request. Redirect will create a new request.'
Set a param in your _forward call, which you can check for in your second form: Such as 'form' => 2. More information.
Use the built in multipage forms that are included in Zend_Form out of the box.
You could always set a class variable in action one and if it is true, don't run the code in action two.
Something like:
class FooController extends Zend_Controller_Action {
private $_fromAction1 = false;
...
public function form1Action(){
if ($this->getRequest()->isPost()) {
// save data from form1 in database
$this->_fromAction1 = true;
$this->_forward('form2');
}
// display form1
}
public function form2Action(){
if ($this->getRequest()->isPost() && !$this->_formAction1) {
// save data from form2 in database
$this->_forward('somewherelese');
}
// display form2
}
}
This last option did not work for me.
$this->_forward() creates a new instance of the controller, so setting a variable in the first instance does not affect the one in the new.
My solution was making $_fromAction1 static to share the variable between the 2 instances.
class FooController extends Zend_Controller_Action {
private static $_fromAction1 = false;
...
public function form1Action(){
if ($this->getRequest()->isPost()) {
// save data from form1 in database
FooController::_fromAction1 = true;
$this->_forward('form2');
}
// display form1
}
public function form2Action(){
if ($this->getRequest()->isPost() && !FooController::_formAction1) {
// save data from form2 in database
$this->_forward('somewherelese');
}
// display form2
}
}