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"'); ?>
Related
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
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>
I am working on a code segment that is a messaging function next to a list of names. On the page there is an envelope and when you click it a pop-up window appears with a text area inside of it. I would like to be able to fill that textarea with characters and send it as a message using my already functioning sendMessage function. I know my sendMessage function works and I've isolated the issue to the return given by the submit button. How do I get my submit button to POST the textarea to the page (keep in mind there are 2+ forms on this page). The code looks like this:
if (empty($_POST) === false) {
print_r($_POST);
$blah = $_POST;
echo "<script>window.top.location='asd.$blah'</script>";
}
if (empty($_POST['Send']) === false) {
echo "<script>window.top.location='../hidden/PNMasdd.php?gpa=$var1&year=$var2&major=$var3&sport=$var4'</script>";
echo 'YOU ARE IN THE SENDING MESSAGE FIELD';
if( empty ($_POST['message_full']))
{
$errors[] = 'All fields must be filled in!';
//print_r($errors);
}
if(empty($_POST) === false && empty($errors) === true)
{
$receiver_id = $temp_user['id'];
$sender_id = $user_data['id'];
$type = 0;
if(empty($is_Convo))
{
$is_Convo = 0;
}
$blahVar = $user_data['id'] . ',';
$message = str_replace("\r\n", "<br>", $_POST['message_full']);
$message_data = array(
'sender_id' => $user_data['id'],
'receiver_id' => $receiver_id,
'message_full' => $message,
'is_opened' => $blahVar,
'isConvo' => $is_Convo,
'type' => $type
);
//Put data limit code here
send_message($message_data);
$my_exten = "Messages/messages.php";
$noti_data = array(
'id_receive' => $receiver_id,
'id_sent' => $user_data['id'],
'type' => 1,
'exten' => $my_exten
);
notify($noti_data);
echo '<center>';
echo '<div class="alert alert-info">
<strong>It sent!</strong> You have sent a message successfully!
</div>
';
echo '</center>';
}
else{
echo output_errors($errors);
}
}
?>
<form id="wow" name="wow" action="" method="POST">
<div class="row">
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<center>
<textarea maxlength="100000" data-msg-required="Please enter your message." rows="10" cols="100%" class="form-control" name="message_full" id="message_full"></textarea>
</center>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<table width=90%><td width=45%><button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button></td><td width=45%>
<button type="submit" value="Send Message" name="Send" onclick="document.getElementById('wow').submit()" class="btn btn-primary">Send</button>
As pointed out in the comments, the buttons need to be inside your form.
Your setup is a bit odd for my taste, but try this out.. it will mostlikely need some tweaks and i'm not sure about the cancel button..
<form id="wow" name="wow" action="" method="post" >
<div class="form-group required">
<div class="col-md-12">
<textarea name="message_full" id="message_full" rows="10" cols="100%" class="form-control" maxlength="10000" placeholder="Please enter your message." autocomplete="off"></textarea>
</div>
</div>
<div class="buttons"> <!-- add css for this or change the class to yours.. -->
<input class="btn btn-default" data-dismiss="modal" value="Cancel" />
<input class="btn btn-primary" type="submit" value="Send Message" />
</div>
</form>
As #Barmar just said, you don't have any field named 'Send'. You should change:
if (empty($_POST['Send']) === false)
to:
if (empty($_POST['message_full']) === false)
(Edit)
Only the fields inside your form will get to $_POST superglobal, the submit button will not get there
I have been searching through various questions on the site with no luck. The closest I got to an answer, as far as I can tell, was through the following question: CodeIgniter's form action is not working properly.
The problem is that when I press the login button nothing happens so the action property in the HTML form is not being triggered. I have looked at my routes as well with no luck.
The HTML code is in my view folder and is the following:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-body">
<form role="form" method="post" action="<?php echo base_url() ?>index.php/login">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" type="username" required>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" required>
</div>
<a type="submit" id="login-button" style="navy" class="btn btn-lg btn-success btn-block">Login</a>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
My controller is called pages.php, and it's function, login is the following:
public function login()
{
$this->load->helper('form');
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($username != false && $password != false)
{
$loginDetails = $this->pages_model->retrieveLoginDetails($username, $password);
if ($loginDetails != false)
{
if ($loginDetails['username'] == $username && $loginDetails['password'] == $password)
{
$this->load->view ('home');
}
else
{
$this->view();
echo "details dont match";
}
}
else
{
$this->view();
echo "nothing received from db";
}
}
else
{
$this->view();
echo "no details entered";
}
}
I am only concerned with going to the home page. By calling the view function I am just returning to the login screen. I will adjust the naming appropriately once I can get this to work. The pages model contains the following function to retrieve the login data from the database:
public function retrieveLoginDetails ($username, $password)
{
$loginDetails['username'] = $this->db->get_where('user_details', $username);
if (! empty ($loginDetails['username']))
{
$loginDetails['password'] = $this->db->get_where('user_details', $password);
return $loginDetails;
}
return false;
}
Any help would be greatly appreciated. Thanks.
Use
<input type="submit" value="Login" class="btn btn-lg btn-success btn-block" />
In place of
<a type="submit" id="login-button" style="navy" class="btn btn-lg btn-success btn-block">Login</a>
To know more check out this : http://www.w3schools.com/tags/tag_a.asp
I don't know direct anwser, but did you check what exactly is your server returning and where are data beeing sent. LiteBug FTW ;)
If there isn't any data beeing sent, you should probally check your .js files.
I have 4 buttons,and also an exportexcel button.I want to set the excel filename.If i clicked getToday button, i want to set the today date to the excel.
<div class="span3 btns_state">
<div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a">
<button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>
<button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
<button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
<button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
</div>
</div>
My php code to get the dates.
$str = $_GET['getTday'];
if($str == 'getToday')
{
$var=$today;
}
else
{
$var=$this_week;
}
I want to retrieve the dates corresponding to the button i clicked,but only else part is working.
Here is the excel export.
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), Report-<?php echo $var?>.xlsx");
You can use query string to pass the value of clicked button
refer the "Today" button below.
You can set the value of variable "$var" to your execel or anything.
[Note:I done in the same page,create "test.php" and paste the following code and try,it will works well]
Thank You.
<?php
//Assume Variables $today and $this_week like below
$today = date('Y-m-d');
$this_week = "This week";
$var = "";
if(isset($_GET['getTday'])):
$str = $_GET['getTday'];
if($str == 'getToday')
{
$var=$today;
}
else
{
$var=$this_week;
}
endif;
echo $var;
?>
<div class="span3 btns_state">
<div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a" >
<button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show('getToday')">Today</button>
<button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
<button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
<button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
</div>
</div>
<script>
function show(val)
{
if(val == 'getToday')
{
location.href = "test.php?getTday=getToday";
}
}
</script>
Make button type submit with form tag
<form>
<button type="submit" name="getTday">
and so on...
</form>
Then you will get in php like $_GET['getTday'] this will get name attr of field so keep id and name same
else you need to use jquery/js to get id of button
add value attribute in your button like this value="getToday".
You can get this in php file.
Example
<button type="button" name="getTday" id="getToday" value="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>
Using jquery click event to perform your action. You have to remove all click event inside html
$(".btn.btn-info.rep_data.tip-bottom").click(function(){
var name=$(this).attr("name");
// you can get what ever it is
// this.id;
// this.value
});
DEMO
NOTE: Dont write event in html it is not good practis