i am trying to create an PDF using Dompdf, in my program i have model query with a dynamic parameter based on the input in the form, but when i click on my button to send the value from the select button to the controller, the data not been send properly, any idea why? below are my code
<form class="form" method="get" action="<?=site_url()?>/laporan/pdfdownload" id="myID" name="myName">
<select id="sel1" class="form-control">
<option disabled selected="selected">Pilih</option>
<?php foreach ($kerja as $rows){?>
<option value="<?php echo $rows->id_project?>"><?php echo $rows->id_project.' - '.$rows->nama_project ?></option>
<?php }?>
</select>
<select id="sel2" class="form-control">
<option disabled selected="selected">Pilih</option>
<?php foreach ($item as $rows){?>
<option value="<?php echo $rows->id_project?>"><?php echo $rows->id_project.' - '.$rows->nama_project ?></option>
<?php }?>
</select>
<button id="filter_button" style="margin-top: 26px;margin-left: 28px;width: auto" name="filter_button" type="submit" class="form btn btn-danger"><i class="fa fa-search"></i> Search</button>
</form>
and here is my controller
public function pdfdownload(){
//If i click submit then all of the post didnt get sended
$one = $this->input->post('sel1');//no value at all, anyone know why?
$two = $this->input->post('sel2');//no value at all, anyone know why?
$data['real'] = $this->report_m($one,$two)->row();
htmlcontent = $this->load->view('laporan/download/laporan3.php',$data,true);
include(APPPATH."third_party/dompdf/autoload.inc.php");
// require_once APPPATH . 'third_party/dompdf/autoload.inc.php';
$dompdf = new Dompdf\Dompdf();
$dompdf->load_html($htmlcontent);
$dompdf->set_paper("f4");
$dompdf->render();
$dompdf->stream("cobadlu.pdf",array("Attachment" => false));
exit(0);
}
enter code here
In your HTML form, you need to use name attribute, and not only ID :
<select id="sel2" name="sel2" class="form-control">
First of all there is a mistake in your form:
<form class="form" method="get" action="<?=site_url()?>/laporan/pdfdownload" id="myID" name="myName">
You given the method='get' here, please change it to 'post'.
Second you are not include the 'name' attribute to the input type so after submit no data will send. So add the name attribute like that:
<select id="sel1" name="sel1" class="form-control">
<select id="sel2" name="sel2" class="form-control">
Related
I am passing a variable from page1 to page2 using GET and it's already working. However, I also use another get in the <select> <option> on page2 which means when I click an item in the option, the value I get from page1 disappears and becomes undefined since the address bar changes. I want the variable I get from page1 to be compared on SQL where clause. I can't think of a way on how to solve this, I'm not really knowledgeable in PHP, can you help me?
Here is my code(I remove some unnecessary lines): page1
<form method="get" action="home.php">
<div class="form-group">
<input id="codehe" class="form-control" type="codehe" name="codehe" placeholder="Class Code">
</div>
<div class="form-group">
<input class="form-control button" type="submit">
</div>
</form>
page2 (this is how i get the value from page1)
<?php
$codehe = $_POST['codehe'];
echo $codehe;
?>
The other GET (form) on page2
<form method="GET">
<select id="state" multiple name="state" onchange='if(this.value != 0) { this.form.submit(); }'>
<option value="ALL">ALL</option>
<option value="<?php echo $row['subjects'];?>"><?php echo $row['subjects'];?></option>
</select>
</form>
<?php
if(isset($_GET['state'])) {
$str = $_GET["state"];
$sql = "SELECT * FROM classvideo WHERE subjects = '$str' AND linkcode = ''";
?>
The traditional way to do things like this (without client-side code) is to put a hidden input in your form on page 2:
<form method="GET">
<select id="state" multiple name="state" onchange='if(this.value != 0) { this.form.submit(); }'>
<option value="ALL">ALL</option>
<option value="<?php echo $row['subjects'];?>"><?php echo $row['subjects'];?></option>
</select>
<!-- Add this line -->
<input type="hidden" name="codehe" value="<?php echo $_GET['codehe'] %>">
</form>
I dont know where or how to use $_POST to get the values of the forms.
This is the whole code, I uploaded it on GitHub if you want to see the whole thing
This is the file I am trying to get the values out of.
new.php
<?php
if (!empty($_POST) and isset($_POST['actiune']))
{
$actiune = isset($_POST['actiune']) ? $_POST['actiune'] : NULL;
switch($actiune){
//CASE 1
case 'addElev': echo '<div class=dbFormText>Adauga elev</div><div
class="databaseform"><form action="" method="post">
<input type="text" name="numeElev" placeholder="Nume elev"/>
<input type="text" name="orasElev" placeholder="Localitate"/>
<select name="sexElev">
<option value="Baiat">Baiat</option>
<option value="Fata">Fata</option></select>
<input type="text" name="tlfElev" placeholder="Nr. de telefon"/>
<input type="text" name="birthdayElev" placeholder="Nastere(DD-MM-YYYY)"/>
<input type="submit" value="Submit">
</form></div>';
break;
}
}
?>
This is the page of the first dropdown, which gives me the value of the switch
adminpanel.html
<div class="dropdowns">
<form action="" method="post">
<select name="actiune" onchange="this.form.submit()">
<option>Selecteaza actiunea</option>
<option value="addElev">Adauga elev</option>
<option value="addNota">Adauga nota</option>
<option value="addAbsenta">Adauga absenta</option>
<option value="addTeza">Adauga teza</option>
<option value="deleteElev">Sterge elev</option>
<option value="deleteNota">Sterge nota</option>
<option value="deleteAbsenta">Sterge absenta</option>
<option value="deleteTeza">Sterge teza</option>
<option value="modifyElev">Modifica elev</option>
<option value="modifyTeza">Modifica teza</option>
<option value="modifyPurtare">Modifica nota purtare</option>
</select>
<?php include('new.php') ?>
</div>
When you submit a form that has a method of post, e.g.
<form method="post">
(note: action="" is redundant and can be left out)
the target page (in this case, itself) will be provided with the $_POST array.
You can dump the entire array to look at the values by using:
if (!empty($_POST) and isset($_POST['actiune']))
{
var_dump($_POST);
}
This array should contain all the values from within the <form> tag, provided a name has been set (which will be used as the 'key' in the array).
Not sure what is the switch for, added the fetch of postvars at the top of code. I am sure you can do some php to make sure vars are set. Also actiune is not a postvar that is its not the name of anyof the input fields so dont do $_POST['actiune']. it wont work. Else you have to add a hidden field, I did it here for you.
<?php
if (!empty($_POST) {
$numeElev = $_POST['numeElev'];
$orasElev = $_POST['orasElev'];
$sexElev = $_POST['sexElev'];
}
if (!empty($_POST) and isset($_POST['actiune']))
{
$actiune = isset($_POST['actiune']) ? $_POST['actiune'] : NULL;
switch($actiune){
//CASE 1
case 'addElev': echo '<div class=dbFormText>Adauga elev</div><div
class="databaseform"><form action="" method="post">
<input type="text" name="numeElev" placeholder="Nume elev"/>
<input type="text" name="orasElev" placeholder="Localitate"/>
<input type="hidden" name="actiune" placeholder="1"/>
<select name="sexElev">
<option value="Baiat">Baiat</option>
<option value="Fata">Fata</option></select>
<input type="text" name="tlfElev" placeholder="Nr. de telefon"/>
<input type="text" name="birthdayElev" placeholder="Nastere(DD-MM-YYYY)"/>
<input type="submit" value="Submit">
</form></div>';
break;
}
}
?>
I have a simple HTML select option in which it should automatically send OnChange. The form seems to send or "Reload the page" should I say. I am not getting ANY data the other end. I have tried POST and GET I have renamed every section of the forms data and changed the entire if(isset() information. Any ideas why I am not getting any data?
FORM:
<?php
$system1 = mysqli_fetch_assoc(mysqli_query($conn,
"SELECT * FROM ap_system_status WHERE system_id = '1'"));
$system_id_1 = $system1['system_id'];
$system_name_1 = $system1['system_name'];
$system_status_1 = $system1['system_status'];
?>
<strong><? echo $system_name_1; ?></strong>
<div align="right" style="float:right">
<div class="form-group">
<form action="" method="GET" id="system_status" name="system_status">
<input type="hidden" id="system_id" value="<? echo $system_id_1; ?>" />
<select class="form-control" onchange="this.form.submit()" id="status">
<option disabled="disabled" selected="selected" hidden="hidden"><? echo $system_status_1; ?></option>
<option value='<i class="fa fa-exclamation-triangle" style="color:#F60"></i> Experiencing Errors'>Experiencing Errors</option>
<option value='<i class="fa fa-exclamation-triangle" style="color:#F60"></i> Being Updated'>Being Updated</option>
<option value='<i class="fa fa-exclamation-triangle" style="color:#F60"></i> Maintenance Mode'>Maintenance Mode</option>
<option value='<i class="fa fa-times-circle-o" style="color:#F00"></i> System Offline'>System Offline</option>
<option value='<i class="fa fa-check-circle-o" style="color:#090"></i> Good Service'>Good Service</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
DATA COLLECTION (Very basic but only testing!!):
<?php
if(isset($_POST['system_status'])){
$system_id = $_POST['system_id'];
$status = $_POST['status'];
echo $system_id;
echo $status;
}else{
}
?>
A couple of changes to your form and PHP should get this working. In order for the form elements to be submitted with the form, they must have name attributes, and the form method must match the superglobal ($_GET or $_POST) you are accessing in PHP.
<!--Change the form method to match what you are using in your PHP-->
<form action="" method="POST" id="system_status" name="system_status">
<!--Add a name to this input-->
<input type="hidden" id="system_id" value="<? echo $system_id_1; ?>" name="system_id" />
<!--Add a name to this select-->
<select class="form-control" onchange="this.form.submit()" id="status" name="status">
<option disabled="disabled" selected="selected" hidden="hidden"><? echo $system_status_1; ?></option>
<!--Not related to your question, but switch the value attribute with the
option text so you can see your icons and get the value I assume you expect-->
<option value="Experiencing Errors"><i class="fa fa-exclamation-triangle" style="color:#F60"></i> Experiencing Errors</option>
...
</select>
<noscript><input type="submit" value="Submit"></noscript>
I would actually not recommend getting rid of the isset check altogether, but modifying it so that it actually verifies that the values you are going to use are present.
<?php
if (!empty($_POST['system_id']) && !empty($_POST['status'])) {
$system_id = $_POST['system_id'];
$status = $_POST['status'];
echo $system_id;
echo $status;
} else {
// error handling for missing values
}
I have a select tag with different values as shown below.
I want to send the selected value to a PHP page as a POST variable or any other way.
Is this possible?
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
Put your select inside a form. Give the form an action that is a php file. give it the method of post and include a <input type="submit" value="Submit"> inside the form as well.
Then, in your php file you will access the $_POST array
echo $_POST['city'];
If you'd like to submit it without the button, you'll need to use javascipt's onChange event.
Yes, and it's very simple. You have to use the from tag : http://www.w3schools.com/html/html_forms.asp and learn a little of PHP and HTML basic interaction
<form action = 'myPage.php' method = 'post'>
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
<input type = 'submit' name = 'send' value = 'send'/>
</form>
(I also added a button son send data)
in myPage.php :
<?php
if(isset($_POST['city'])){
echo isset($_POST['city'];
}
?>
I am trying to use HTML select dropdowns to help sort the search results on my website and I am having some trouble. In the code below, I specifically select Option1 and when I try to echo the result after I submit the form, it always echo's 'FAIL'. I was wondering if someone can help me understand what I am doing wrong and what is the proper way to retrieve the data from the option the user selected, after the form was submitted?
<?php
echo '<form method="post" action="search.php">
<select>
<option name="one">Option1 </option>
<option name="two">Option2</option>
</select>
<input type="text" name="searchword" />
<input type="submit" value="Search" />
</form>';
if(isset($_POST['one'])){
echo 'Option1 is set';
}else{
echo 'FAIL';
}
?>
thank you
This is because the name attribute goes with the select tag.
<select name="dropdown">
<option>Option 1</option>
<option>Option 1</option>
</select>
if(isset($_POST['dropdown'])) {
echo $_POST['dropdown']; //echoes 'Option 1'
}
If you like, you can add a value attribute to the option element, but you don't have to.
If you do
<option value="foobar">Option1</option>
The form will post foobar and not Option1.
<?php
echo '<form method="post" action="search.php">
<select name="my_option">
<option value="one">Option1 </option>
<option value="two">Option2</option>
</select>
<input type="text" name="searchword" />
<input type="submit" value="Search" />
</form>';
echo "My option value is : " . $_POST['my_option'];
?>
You need to name your select tag and access that instead.
<select name="options"></select>
echo $_POST['options']; will give you your selected option
Instead of name="one" an option needs a
value="myvalue"
and your select tag needs an
name="nameofthisthinghere"