How to link page with button click in Codeigniter? - php

I am trying to load a page on click,
I created an email verification link which open the page and updates my Database all it works fine, but the page contains a button which i want to be clicked by user and open first page which have login window.
My verify.html:
<div class="container container-table">
<div class="row vertical-center-row">
<div class="text-center col-md-4 col-md-offset-4" style="background:blue">
<h3> Thankyou For Veryfing</h3>
<p>You Are Verified</p>
<form action="login.php/verify_to_login" method="post">
<button type="submit" class="btn btn-success" >Sign Up>Go To Login</button>
</form>
</div>
</div>
</div>
My Controller function which loads the verify page like this : http://localhost/index.php/login/verify/1567af19e10ce4
public function verify($VerificationCode){
$this->load->model('My_model');
$this->load->helper('url');
$this->My_model->verifymail($VerificationCode);
/* Send to the verification page */
$this->load->view("verify.html");
}
This is my verify_to_login() function which i want when i click on button it should open header.html, This should work like http://localhost/index.php/login/verify_to_login
but instead this it is showing http://localhost/index.php/login/verify/login.php/verify_to_login when i click on the button
public function verify_to_login(){
$this->load->view("header.html");
}
I am unable to understand why is this happening.?? :(

On html
<form method="" action="<?php echo base_url(); ?>​controller_name/function_name">
<button id="submit-buttons" type="submit" ​​​​​>Submit 1</button>
</form>
And on Controller
function functionname(){
$this->load->view('some_view')
}
So basically your controller is fine, so just fix the button by putting the controller name and then the function name and all should work hopefully.

try
this
<button type="submit" class="btn btn-success" onclick="window.location.replace('YOUR_LINK_HERE');">Sign Up>Go To Login</button>
OR
<button type="submit" class="btn btn-success" onclick="window.location.href('YOUR_LINK_HERE');">Sign Up>Go To Login</button>

Related

follow and unfollow like instagrm system in codeigniter

I have work one project and there user can follow and unfollow another user like instagram. I had done to user listing and follow and unfollow system. But when i follow more than one user, in user listing panel follow and unfollow button both show. if i follow 3 user then user listing panel 3 button show. One button is Unfollow and two button is follow shows. My view side code is below:
<?php foreach($latestCompany as $companyRow):?>
<div class="col-md-6">
<div class="home-list-pop">
<div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
<img src="<?= base_url('uploads/company_logo/'.$companyRow['company_logo']);?>" alt="" />
</div>
<div class="col-lg-9 col-md-9 col-sm-8 col-xs-12 home-list-pop-desc">
<h3><?= $companyRow['company_name'];?></h3>
<h4><?= $companyRow['company_city'].', '.$companyRow['company_country'];?></h4>
<div class="btn-listing">
<?php foreach($agentNetwork as $agentNetworkRow):?>
<?php if($agentNetworkRow['follower_id'] == $memberId && $agentNetworkRow['following_id'] == $companyRow['member_id']):?>
Unfollow
<?php else:?>
Follow
<?php endif;?>
<?php endforeach;?>
</div>
</div>
</div>
</div>
<?php endforeach;?>
My Controller code:
<?php
public function index(){
$member_userdata = $this->session->userdata('isMemberLoggedIn');
$memberId = $member_userdata['memberId'];
$latestCompany = $this->member_model->getLatestMember();
$agentNetwork = $this->member_model->getAgetNetworkById($memberId);
$this->load->view('includes/header');
$this->load->view('index', ['latestCompany'=>$latestCompany, 'agentNetwork'=>$agentNetwork]);
$this->load->view('includes/footer');
}
?>
My Model code
public function getLatestMember(){
$this->db->order_by('member_id', 'DESC');
$query = $this->db->get_where('li_members', array('membership_status'=>'Y'));
return $query->result_array();
}
public function getAgetNetworkById($memberId){
$query = $this->db->get_where('li_agent_network', array('follower_id'=>$memberId));
return $query->result_array();
}
Below i provide sample image
Above image i follow both user, so i want show only unfollow button.
First you need to use the <form> Tag and you just need to use $(this).closest("form").serialize(); to get closest form data and then simply use $(".mybtn").not($this).attr("disabled", false); to enable all button and not the button which is pressed.
Demo Code:
$(document).ready(function() {
//Stops the submit request
$("#form").submit(function(e) {
e.preventDefault();
});
//checks for the button click event
$(".mybtn").click(function(e) {
var $this = $(this)//use as selector
dataString = $(this).closest("form").serialize(); //get closest form only
console.log(dataString)
$this.attr("disabled", true); //set attr disable
//enable all button not (this)
$(".mybtn").not($this).attr("disabled", false);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<form name="form">
<button class="btn btn-success user_status mybtn" >FOLLOW</button>
<input type="hidden" name="followId" value="1">
<input type="hidden" name="userId" value="1">
</form>
<form name="form">
<button class="btn btn-primary user_status mybtn" >UNFOLLOW</button>
<input type="hidden" name="followId" value="2">
<input type="hidden" name="userId" value="1">
</form>

Send data from three forms to the controller

I created three different forms they need to be separated because they are collapsed in different buttons. It happens that I would like my controller to receive data from the three forms when I click on a submit button on the third form. Is it possible to receive input data from all forms with a single submit in Laravel?
Each form is inside a button identified by a data-target. Example:
<div class="container" id="myGroup">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#entidade" role="button" aria-expanded="false" aria-controls="entidade">
Entidades
</button>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#dirigente1" role="button" aria-expanded="false" aria-controls="dirigente1">
Dirigente 1
</button>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#dirigente2" role="button" aria-expanded="false" aria-controls="dirigente2">
Dirigente 2
</button>
<form class="collapse" id="entidade" data-parent="#myGroup" method="post" action="/entidades/store">
.
.
</form>
<form class="collapse" id='dirigente1' data-parent="#myGroup" method="post" action="/entidades/store">
.
.
</form>
<form class="collapse" id='dirigente2' data-parent="#myGroup" method="post" action="/entidades/store">
.
.
</form>
</div>
Controller:
public function store(Request $request){
}
You just have to put all your forms into one, and that means have only one form tag that will send a POST request to your controller.
I would suggest implementing the logic in your controller that would handle empty fields and save only those fields that are not empty (i.e. if you leave first two forms blank and submit only the third one)
You can still keep all 3 submit buttons, but make sure to merge all forms into one, so you have only one form tag in a page like this:
<form method='POST' action='...'>
...form 1 inputs...
...submit button 1
...form 2 inputs...
...submit button 2
...form 3 inputs...
...submit button 3
</form>
thanks guys, I solved the problem leaving everything in a single form.

Show search results on another view with CakePHP

I'm working with CakePHP now and I need to do a search with one view and then send the data to another action on the same controller, that will trigger another view with the results of that search. The thing is, on the search screen, there's also a table showing some data of the same model, and I believe that's one big problem.
So right now, it's here what I got:
public function busca() {
$emergency = TableRegistry::get('EmergencySheets');
$manufacturers = TableRegistry::get('Manufacturers');
$data = $this->request->is('get') ? $this->request->query : $this->request->getData();
$query = $emergency->find()
->select(['id', 'data_atualizacao_fabricante', 'tarja', 'manufacturer_id', 'nome_comercial'])
->where('EmergencySheets.data_atualizacao_fabricante')
->order(['data_atualizacao_fabricante'=>'DESC'])
->limit(7);
$manufacturer_query = $manufacturers->find()
->select(['id','nome'])
->where($query->manufacturer_id = 'id');
$manufacturer = $manufacturer_query->toArray();
$sheets = $query->toArray();
$this->set('manufacturers', $manufacturer);
$this->set('sheets', $sheets);
if($data){
return $this->redirect(['action' => 'ficha' , $data]);
}else{
return $this->redirect(['action' => 'busca404']);
}
}
How can I handle this?
Thank you all!
Edit:
Forgot to mention, but the $data variable always come empty on the form, even when I type something on the form input. Here's the view code, too!
<section class="search-section">
<div class="container px-0">
<div class="search-wrapper">
<div class="search-title">
<h2><span>Quais produtos</span>você vai transportar?</h2>
<p><span>Pesquise pelos produtos no campo de busca</span>
ou clique nas letras ao lado.
</p>
</div>
<div class="search-bar">
<?=$this->Form->create()?>
<div class="ml-5 bar">
<input type="text" placeholder="Procure várias fichas de uma só vez" class="formcontrol tip"
data-toggle="tooltip" data-placement="top">
<span class="removeClick"><i class="fas fa-times-circle fa-2x"></i></span>
<button type="submit" class="btn"><i class="fa fa-search fa-2x"></i></button>
</div>
<?=$this->Form->end()?>
<div class="ml-5 alfabeto text-center">
<button href="#A">A</button> <button href="#B">B</button> <button href="#C">C</button> <button href="#D">D</button>
<button href="#E">E</button> <button href="#F">F</button> <button href="#G">G</button> <button href="#H">H</button>
<button href="#I">I</button> <button href="#J">J</button> <button href="#K">K</button> <button href="#L">L</button>
<button href="#M">M</button> <button href="#N">N</button> <button href="#O">O</button> <button href="#P">P</button>
<button href="#Q">Q</button> <button href="#R">R</button> <button href="#S">S</button> <button href="#T">T</button>
<button href="#U">U</button> <button href="#V">V</button> <button href="#W">W</button> <button href="#X">X</button>
<button href="#Y">Y</button> <button href="#Z">Z</button><button href="#0-9">0-9</button>
</div>
</div>
</div>
</div>
I would use the same function and template for the search form and results. Eliminate the whole if section with redirects, only do the search if there is data to search on, and change your view to check whether there are results to display. Something like this:
$data = $this->request->is('get') ? $this->request->getQueryParams() : $this->request->getData();
if (!empty($data)) {
// Do your searches using $data here, set the results for the view
$this->set('results', $results);
}
Then in your template, you have it like you've shown, but add a section with
if (isset($results)):
// Display your search results here
endif;
Please consider that you are puting code after the line:
return $this->redirect(['action' => 'busca404']);
}
In that case all those lines wont be executed in any case because you are forcing redirects either if the request is "get" or not. So all that code wont be executed.
I think that you need to define the conditions to redirect to the "ficha" action and in which conditions remain in to the "busca" action

Codeigniter, Submit "button" missing instructions from controller or model?

the submit "button" isn´t working properly, I know there must be something missing, the problem is Idk what is it...
The main idea is to insert information, then do a refresh displaying it in a table below, all in the same "page", the "submit" doesn´t save :(.
Thanks in advance.
Part of the code in Model:
function create_gei()
{
$data['theyear'] = $this->input->post('theyear');
$data['qty_alumni'] = $this->input->post('qty_alumni');
$data['emanations'] = $this->input->post('emanations');
$data['temperature'] = $this->input->post('temperature');
$this->db->insert("pdc_factor_gei", $data);
}
Part of the code in Controller:
function btn_create_gei()
{
$this->model_gas_consum->create_gei();
$submit = $this->input->post('send');
if($submit=='repeatgei')
{
redirect(current_url("gas_consum/factor_gei/"), 'refresh');
}
else
{
redirect("gas_consum/home_gas/");
}
}
Part of the code in View "button":
<?php echo form_open("gas_consum/factor_gei"); ?>
<div class="row">
<div class="col-md-6 text-right">
<button
name="send" value="repeatgei" class="btn" type="submit">
<span class="glyphicon glyphicon-refresh"></span> Save</button>
</div>
<?php echo form_close(); ?>
Try this
<input type="submit" name="send" value="repeatgei" class="btn">
Try this, change your
<button name="send" value="repeatgei" class="btn" type="submit">
<span class="glyphicon glyphicon-refresh"></span> Save</button>
To this
<?php echo form_submit('send', 'repeatgei', 'class="btn"'); ?>

Get MySQL data to bootstrap model

I have a list of users on my web page echoed using a PHP loop. The names are links look like this.
{$user['username']}
So, when I click on each user, I am taken to user.php page.
user.php displays each user's information based on the query parameter $user['id'] in the URL. Using $_GET['id'] method.
So, that's the current situation I have.
What I now want to do is, display user's information in a Bootstrap Model
So, how could I get that query parameter into the Bootstrap model. And do the same PHP processes to get the same functionality ?
If you have google this you can get number of results related to it.
Here is code seems to be referred from one of this question passing-data-to-a-bootstrap-modal
HTML
<a data-toggle="modal" data-id="ISBN564541" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>
<div class="modal hide" id="addBookDialog">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>some content</p>
<input type="text" name="bookId" id="bookId" value=""/>
</div>
</div>
Javascript
$(document).ready(function () {
$(".open-AddBookDialog").click(function () {
$('#bookId').val($(this).data('id'));
$('#addBookDialog').modal('show');
});
});

Categories