I'm new to php and codeigniter. I have this task that i'm working on right now which is a hostel management system. the student has the ability to choose the meal they want to eat by selecting on it, all im trying to do is to disable the select button after they click on it, in other words the student can choose a specific meal once.
here's my code:
<td><div><?php echo $row['type'];?></div></td <td><div><?php echo $row['content'];?></div></td>
<td><div><?php echo $row['date'];?></div></td>
<td align="center">
<?php $is_selected=$this->db->get_where('selected_meal', array( 'meal_id' => $row['meal_id'],'student_id'=>$this->session->userdata('student_id')))->row()->delivered;
<a data-toggle="modal" href="#modal-form" onclick="modal('order_meal',<?php echo $row['meal_id'];?>)" class="btn btn-gray btn-small">
<i class="icon-wrench"></i> <?php echo get_phrase('select');?>
</a>
<?php ?>
</td>
Here is sample form, button and javascript. You need to modify it to fit your needs.
<form name="myForm" id="myFormId" class="form-horizontal" method="post" action="<?=base_url('invoice/create_invoice');?>">
<input type="submit" id = "formSubmit" class="btn btn-primary" value="Submit">
</form>
<script type="text/javascript">
document.getElementById('myFormId').onsubmit = function() {
document.getElementById("formSubmit").disabled = true;
}
</script>
Give a class to element, which you want to select. Ex 'select-meal'.
$('.select-meal').click(function(){
$(this).attr('disabled', 'true');
})
It seems you are using bootstrap, you can add class "disabled" on click submit
Or, try this, add class dis-btn and write script on event click
$('.dis-btn').prop('disabled', true);
Related
hi i want to have two submit button in one form in code igniter. is it possible? i want to make two buttons which will do the same thing, add data into the database, the only difference of the buttons is on which page they will redirect.
here is my codes,
<?php
echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3));
?>
// some textboxex,
<div class="box-body">
<div class = 'col-md-6 col-sm-offset-6'>
<button class="btn btn-info fa fa-save" type="submit">  Save</button>
<a href = '<?php echo base_url().'EmpFamilyInfo/other_childinfo/'.$this->uri->segment(3); ?>' class = 'btn btn-primary fa fa-save' >  Add Another</a>
<a href = '<?php echo base_url().'EmpFamilyInfo/parentsinfo_father/'.$this->uri->segment(3); ?>' class = 'btn btn-danger fa fa-arrow-circle-right'>  Skip</a>
<?php
echo form_close();
?>
</div>
</div>
i have made this code which the first link echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3)); what i wanted this to do is
public function other_childinfo(){
$this->form_validation->set_rules('NAME', 'Name of Child' ,'trim|required|max_length[100]');
if($this->form_validation->run($this) == FALSE){
$this->child_info();
}else{
if($query = $this->EmpFamilyInfo_Model->insert_childinfo()){
redirect('EmpFamilyInfo/child_info/'.$this->uri->segment(3));
}else{
$this->child_info();
}
}
}
but the error is,that it does not have post data. how can i make this link a submit button but it will go to different function or how can i make it have the post data?
this question ahs been answered already on this site, so this response is not mine, just quoting for you:
This uses javascript so keep in mind users who have this disabled will not be able to use this solution.
<script type="text/javascript">
function submitForm(action)
{
document.getElementById('form1').action = action;
document.getElementById('form1').submit();
}
</script>
...
<input type="button" onclick="submitForm('page1.php')" value="submit 1" />
<input type="button" onclick="submitForm('page2.php')" value="submit 2" />
I have two php page.I'm using Bootstrap, php and mysql. In the first page I load three objects into div from mysql database of the user logged. To do this I'm using the next code:
<div class="container">
<div class="row">
<?php
require_once('function.php');
conectar('localhost', 'root', '', 'mydb');
$consulta1 = mysql_query('SELECT id FROM user WHERE username="'.$_SESSION["name"].'"');
$result = mysql_query('SELECT * FROM finc WHERE Usuario_idUsuario="'.$_SESSION["idUser"].'"');
if ($row = mysql_fetch_array($result)){
do{
echo '<div class="col-lg-4">' ;
echo '<img class="center-block img-circle" src="data:image/gif;base64,R0lGODlhOw=="
alt="Generic placeholder image" style="width: 140px; height: 140px;">';
echo '<h2 class="text-center">'.$row['name'].'</h2>';
echo '<p align="center">'.$row['data'].'</p>';
echo '<p align="center">'.$row['tao'].'</p>';
echo '
<a type="button" class="btn btn-success" href="secondPage.php" role="button">Entrar »</a>
';
echo'</div>';
}while ($row = mysql_fetch_array($result));
} else {
echo "¡ No data for this user!";
<a}
?>
<!-- /.col-lg-4 -->
</div>
<!-- /.row -->
</div>
I need send the id value depending of the button clicked for load the data associated in the next php page. For example, If I click in the second button created in the do-while loop I need send the id=2 to the sencondPage.php. I have searched how to do this, but only find how to send var into url like sencondPage.php?var=2, And I hate this because user can change url... And adding value into session, but on click I haven't get this.
So, how can I pass the corresponding id value when user click in the link??
Thanks!
You could use an html <form>:
<form method="post" action="[URL FOR NEXT PAGE]">
...
<input type="submit" name="value1" value="Button 1" />
<input type="submit" name="value2" value="Button 2" />
</form>
Now if someone clicks the first button it will send them to the next page with the post data: value1=Button%201, and if they click the second button the it will instead be value2=Button%202. In either case any other form elements inside the form will also be submitted via post. With PHP you can retrieve these values using something like:
if ($_POST['value1']) {
...
elseif ($_POST['value2']) {
...
}
This code is a form that results in a link being created with variable $ui.
<form method="post" name="form" onsubmit="#">
Name search:
<input id="ui" type="text" name="ui" />
<input type="submit" class="Submit" value="submit" />
</form>
Then the variable $ui is used to set the value of the data-filter attribute. When you click the link (after the form submits) it goes to "#" which performs a sorting/listing function and reloads the page without refreshing.
<?php if(isset($_POST["ui"]))
{
$ui = $_POST["ui"];
}
$Filterclass = strtoupper(str_replace(" ", "-", $ui));
?>
<a href="#" id="gallery_filter"
data-filter=".<?php echo $Filterclass; ?>">
<?php echo strtoupper($ui); ?></a>
Right now, the form submits and then the link is created, then you can click on it.
It works as-is, but I'd like to have the 'submit' button just open that link, the one with newly updated data-filter attribute.
I would ask this is Wordpress.exchange but I think is too advanced.
I won't write the whole process but modify your existing code as below(assuming jquery is already loaded)
<?php if(isset($_POST["ui"]))
{
$ui = $_POST["ui"];
echo '<script type="text/javascript">
jQuery(document).ready(function(e){
jQuery("#gallery_filter").click();
});
</script>';
}
$Filterclass = strtoupper(str_replace(" ", "-", $ui));
?>
<a href="#" id="gallery_filter"
data-filter=".<?php echo $Filterclass; ?>">
<?php echo strtoupper($ui); ?></a>
I am using the Flexible Map plugin on a wordpress site. The plugin has a form that allows the user to enter their 'from address' to get directions to the location displayed on the map. The form does not have an ID or class (and I am not able to add one).
I would like the user to be able to print the directions once the form is submitted, but I don't want the print button to show up until after the directions have displayed from the user pressing the submit button.
The directions are displayed in a table, so I was thinking I could use JQuery to say that when the table is displayed, then show the print div.
I'm thinking it's something like this, but I'm not sure how to format it based on a table (because the form does not have an ID):
jQuery(document).ready(function($) {
$('#idOfYourForm').on("submit", function () {
$('#print').show();
});
});
Any suggestions are appreciated!
EDIT Here is the code that is generated once the directions submit button is pressed:
<div id="my-dir-div" style="float: left; direction: ltr;">
<form>
<p>
<input type="text" name="from">
<input type="submit" value="Get Directions">
</p>
</form>
<div jstcache="0">
<div class="adp-warnbox" jsdisplay="warnings.length" jstcache="1" style="display: none;">
<div class="warnbox-c2" jstcache="0"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-content" jscontent="$this" jsselect="warnings" jstcache="5"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-c2" jstcache="0"></div>
</div>
<div jseval="setupPanelStep(this, $waypointIndex)" jsvalues="$waypointIndex:0;" jsselect="legs[0].start_address" jstcache="2">
<table id="adp-placemark" class="adp-placemark" jstcache="0">
<tbody jstcache="0">
<tr jstcache="0">
<td jstcache="0">
<img jsvalues=".src:markerIconPaths[$waypointIndex]" jstcache="14" src="http://maps.gstatic.com/mapfiles/markers2/icon_greenA.png">
</td>
<td class="adp-text" jscontent="$this" jstcache="12">211 South Elson Street, Kirksville, MO 63501, USA</td>
</tr>
</tbody>
</table>
</div>
<div jsvalues="$legIndex:$index;" jsselect="legs" jstcache="3" jsinstance="*0">
<div class="adp-legal" jscontent="copyrights" jstcache="4">Map data ©2013 Google</div>
</div>
</div>
<div id="print">
<input id="print" class="printbtn" type="button" value="Print Directions" onclick="return pop_print()">
<script type="text/javascript">
function pop_print(){
w=window.open(null, 'Print_Page', 'scrollbars=yes');
w.document.write(jQuery('div#my-dir-div').html());
w.document.close();
w.print();
}
</script>
</div>
I think you can try this (only if the table with id adp-placemark is available on the page then show it)
$(function(){
if($('#my-dir-div table#adp-placemark').length) $('#print').show();
});
Or, this one
$(function(){
if($('#my-dir-div table#adp-placemark td.adp-text').length) $('#print').show();
});
I'm trying to change the form tag below in order to use jQuery. Already, clicking the buttons changes the display from rows to columns and vice-versa but I want to avoid the page refresh. I'm really new at jQuery and can't honestly say what my mistakes are when trying to change it myself.
<form id="rowsToColumns" action="index.php?main_page=specials&disp_order=1" method="POST">
<input type="hidden" name="style_changer" value="columns"/>
<button type="submit" class="btn btn-large btn-primary" type="button">Change to Column</button>
</form>
<form id="columnsToRows" action="index.php?main_page=specials&disp_order=1" method="POST">
<input type="hidden" name="style_changer" value="rows"/>
<button type="submit" class="btn btn-large btn-primary" type="button">Change to Rows</button>
</form>
I'm also trying for the buttons to call a different stylesheet upon click. This stylesheet is not needed for the display to change from/to rows/columns as I mentioned above. The actual page is written using php as shown below:
<?php $this_page = zen_href_link($_GET['main_page'], zen_get_all_get_params()); ?>
<div id="style_changer">
<?php if($current_listing_style == 'rows') {?>
<form id="rowsToColumns" action="<?php echo $this_page;?>" method="POST">
<input type="hidden" name="style_changer" value="columns"/>
<button type="submit" class="btn btn-large btn-primary" type="button">Change to Column</button>
</form>
<?php } else { ?>
<form id="columnsToRows" action="<?php echo $this_page;?>" method="POST">
<input type="hidden" name="style_changer" value="rows"/>
<button type="submit" class="btn btn-large btn-primary" type="button">Change to Rows</button>
</form>
<?php } ?>
</div>
If the question is "how to change a form in order to use jQuery and avoid the page refresh", then the jquery form plugin is your friend, as it turns any html form into an ajax-powered one.
Simply follow their instructions and you'll get it working in no time (provided your form already works as is).
You can prevent the Default form Submission by preventing the default action on the submit button..
$('button[type=submit]').submit( function(e){
e.preventDefault(); // Stops the form from submitting
});
Well, for a very vague method you can use $.ajax and take advantage of reading the <form>'s pre-existing attributes to decide on submission method and read the elements' values as submissiong data:
$('form').on('submit',function(e){
var $form = $(this);
// submit the form, but use the AJAX equiv. instead of a full page refresh
$.ajax({
'url' : $form.attr('action'),
'method' : $form.attr('type'),
'data' : $form.serialize(),
'success' : function(response){
// process response (make CSS changes or whatever it is
// a form submission would normally do)
}
});
// prevent the normal submit and reload behavior as AJAX is now
// handling the submission
e.preventDefault();
});
However, for this to work you'll need some variation of a stripped-down PHP response just for the purpose of the AJAX request (avoid resending headers, script tags, etc. and just return the raw data that jQuery can use to make a UI decision).