how can I put value of text into the selector inside the form? I need to post text with name=sum into <option value="<?php echo $met->request; ?>"<?php if (isset($method) && $method == $met->request && $currentMethod = $met) { echo ' selected="selected"'; $shownext = true; } ?>><?php echo "$met->description - $met->full_summ $met->valute"; ?></option>
This is my form
<form id="com_telecomax_buydid" action="
<?php echo JRoute::_('index.php',true); ?>" method="post" onsubmit="return telecomax.complete;">
<input type="hidden" name="option" value="com_telecomax" />
<input type="hidden" name="task" value="payment" />
<h3>
<?php if (isset($cart) && $cart) {?>
<p><?php echo JText::_('COM_TELECOMAX_TOTAL_COST_OF_YOUR_CART'); ?>:<span id="com_telecomax_payment_cart_text"><?php echo $cart.' '.JText::_('COM_TELECOMAX_USD'); ?></span></p>
<?php } ?>
<input type="hidden" name="cart" id="com_telecomax_payment_cart" value="<?php echo isset($cart) && $cart ? 1 : ''; ?>" />
<p><label for="com_telecomax_payment_sum"><?php echo JText::_($cart ? 'COM_TELECOMAX_ADDITIONAL_PAY_FOR_TALK' : 'COM_TELECOMAX_DEPOSIT_FUNDS'); ?>:</label>
<input type="text" class="inp-txt" name="sum" id="com_telecomax_payment_sum" value="<?php echo isset($sum) && $sum ? $sum : $default; ?>" /></p>
<p><?php echo JText::_('COM_TELECOMAX_TOTAL_PAYMENT'); ?>:<span id="com_telecomax_payment_total">
<?php echo isset($sum) && $sum ? $sum : $default; ?>
</span> <?php echo JText::_('COM_TELECOMAX_USD'); ?></p>
</h3>
<p><input type="button" id="com_telecomax_payment_getmethod" value="<?php echo JText::_('COM_TELECOMAX_GET_PAYMENT_METHOD'); ?>" />
<p><label for="com_telecomax_payment_method"><?php echo JText::_('COM_TELECOMAX_PAYMENT_METHOD'); ?>:</label></p>
<p><select name="method" id="com_telecomax_payment_method">
<option value=""<?php if (!isset($method) || !$method) echo ' selected="selected"'; ?> disabled="disabled"><?php echo JText::_('COM_TELECOMAX_PLEASE_SELECT_PAYMENT_METHOD'); ?></option>
<?php foreach($this->methods['data'] as $item) { ?>
<optgroup label="<?php echo $item['title']; ?>">
<?php foreach($item['list'] as $met) { ?>
<option value="<?php echo $met->request; ?>"<?php if (isset($method) && $method == $met->request && $currentMethod = $met) { echo ' selected="selected"'; $shownext = true; } ?>><?php echo "$met->description - $met->full_summ $met->valute"; ?></option>
<?php } ?>
</optgroup>
<?php }
?>
</select><input type="hidden" name="paysum" id="com_telecomax_payment_paysum" value="<?php echo isset($currentMethod) ? "$currentMethod->description#$currentMethod->full_summ#$currentMethod->valute" : '##'; ?>" /></p>
<p>
<?php if (isset($cart) && $cart) { ?>
<input type="button" value="<?php echo JText::_('COM_TELECOMAX_BACK'); ?>" onclick="location.href='<?php echo JRoute::_('index.php?option=com_telecomax&task=cart',true); ?>'; return false;" />
<?php } ?>
<input type="submit" value="<?php echo JText::_('COM_TELECOMAX_NEXT'); ?>" id="com_telecomax_payment_next" style="display: <?php echo isset($shownext) ? 'block' : 'none' ; ?>;" />
</p>
</form>
Related
i can call my input value using the foreach ($sub_category as $k => $v) and with the value="<?php echo $v['id'] ?>" <?php if(in_array($v['id'], $sub_category_data)) { echo 'selected="selected"'; } ?>><?php echo $v['name'] ?> but that was in select box my question here is that if i want to convert it into an input type textview how can i get the value?
<div class="form-group">
<label for="sub_category">Category:</label>
<?php $sub_category_data = json_decode($product_data['sub_category_id']); ?>
<select class="form-control select_group" id="sub_category_1" name="sub_category[]" onchange="getSubCategoryData(1)">
<?php foreach ($sub_category as $k => $v): ?>
<option value="<?php echo $v['id'] ?>" <?php if(in_array($v['id'], $sub_category_data)) { echo 'selected="selected"'; } ?>><?php echo $v['name'] ?></option>
<?php endforeach ?>
</select>
</div>
what should i add to call the markup using the sub category id just like in the select box without using the foreach?
<div class="form-group">
<label for="markup">Markup:</label>
<input type="text" class="form-control" id="markup" name="markup" disabled value="" autocomplete="off" placeholder="Markup">
<input type="hidden" class="form-control" id="markup_value" name="markup_value" value="" autocomplete="off">
</div>
Okay guys so my problem here is I need to show some pictures of colors that people can use to pick the color of a cover. Right now its set up to be a drop down and just select the color but we want to switch it over to be the colors.
Here is the code we have set up right now.
<select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"
<?php if(array_key_exists('poid', $_REQUEST)) { ?>
<?php if($option_value['product_option_value_id']==$_REQUEST['poid']){ echo "selected"; }}?>>
<?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?>
<?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
And this is what I've come up with so far.
<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php foreach ($option['product_option_value'] as $option_value) {
//echo $option_value['image'];
if($option_value['image']){ ?>
<div class="button">
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="input-option<?php echo $option['product_option_id']; ?>" />
<img src="<?php echo $option_value['image']?>" />
<label "<?php echo $option_value['name'];?>" </label>
</div>
<?php }}} }?>
Another concern is we have other button options that need to keep working for other selections.
Your <label> syntax is wrong. It should produce:
<label for="button ID">Name</label>
but you're printing:
<label "Name" </label>
Or you can simply wrap a <label> tag around both the button and the name, as I've done below.
<div class="button">
<label>
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" />
<img src="<?php echo $option_value['image']?>" />
<?php echo $option_value['name'];?>
</label>
</div>
I got rid of the id on the button because it was creating duplicate IDs on all the buttons in the same radio group, and is probably not needed.
Other than that problem, I think it should work.
I have the following code in the view of an application I am developing using the codeigniter framework
<?php foreach($query->result_array() as $row){ ?>
<tr>
<?php echo form_open('MainController/AttendanceSet');?>
<input type="hidden" name="child_nric" value="<?php echo $row['child_nric']; ?>"/>
<input type="hidden" name="teachernric" value="<?php echo $_SESSION['username']; ?>"/>
<input type="hidden" name="progcode" value="<?php echo $program; ?>"/>
<td><?php echo $row['child_nric']; ?></td>
<td>
<select name="attendance">
<option value="1" selected="<?php if($selected==1) echo "selected"; ?>">Present</option>
<option value="0" selected="<?php if($selected==0) echo "selected"; ?>">Absent</option>
</select>
</td>
<td> <input type="submit" name="submit" value="Submit"></form></td>
</tr>
<?php } ?>
Have made edit to the code based on the answers below now it is like this
<?php foreach($query->result_array() as $row){ ?>
<tr>
<?php echo form_open('MainController/AttendanceSet');?>
<input type="hidden" name="child_nric" value="<?php echo $row['child_nric']; ?>"/>
<input type="hidden" name="teachernric" value="<?php echo $_SESSION['username']; ?>"/>
<input type="hidden" name="progcode" value="<?php echo $program; ?>"/>
<td><?php echo $row['child_nric']; ?></td>
<td>
<select name="attendance">
<option value="1" selected="<?php if($selected==1) echo "selected"; ?>">Present</option>
<option value="0" selected="<?php if($selected==0) echo "selected"; ?>">Absent</option>
</select>
</td>
<td> <input type="submit" name="submit" value="Submit"></td>
</tr>
<?php echo form_close();} ?>
But the output is still the same
However when the view is loaded, the code comes out like this
<tr>
<form action="http://sms-dev.anovatesoft.com/index.php/MainController/AttendanceSet" method="post" accept-charset="utf-8"></form>
<input type="hidden" name="child_nric" value="A12">
<input type="hidden" name="teachernric" value="T001">
<input type="hidden" name="progcode" value="FEE001">
<td>A12</td>
<td>
<select name="attendance">
<option value="1" selected="">Present</option>
<option value="0" selected="">Absent</option>
</select>
</td>
<td> <input type="submit" name="submit" value="Submit"></td>
</tr>
Notice the difference in the </from> position? In my code I have it after the submit button but when it renders it closes just after the <form> opens making the form useless as I am not able to submit it.
What is the reason behind this strange behavior? And how do I fix it?
The View
<?php
$this->load->helper('form');
?>
<script>
function ListView(){
//if($("#id").val() != "0"){
var formURL = "<?php echo base_url();?>MainController/Attendance/"+$("#program").val();
$.post(formURL).done(function(data){$("#body_view_paste").html(data); });
}
function fire(){
alert("I have been fired");
}
</script>
<div align="center">
<table align="center" style="max-width:80%">
<tr>
<td>Program</td>
<td>
<select id="program" name="program" onchange="ListView()">
<option value="0">Select</option>
<?php
$nricno = $_SESSION['username'];
$sql = "SELECT distinct programs.activities, programs.progcode FROM events
LEFT JOIN programs ON programs.progcode=events.progcode WHERE events.teacher_nric='$nricno'";
$activities = $this->db->query($sql);
foreach($activities->result_array() as $row){?>
<option value="<?php echo $row['progcode'];?>"><?php echo $row['activities'];?></option>
<?php } ?>
</select>
</td>
</tr>
</table>
</div>
<div>
<?php if(isset($program)){
$selected=3;
$query = $this->db->query("SELECT child_nric FROM child_reg_prog WHERE progcode = '$program'");
?>
<table>
<thead>
<tr>
<td>NRIC NO</td>
<td>Attendance</td>
<td>Action</td>
</tr>
</thead>
<?php foreach($query->result_array() as $row){ ?>
<tr>
<?php echo form_open('MainController/AttendanceSet');?>
<input type="hidden" name="child_nric" value="<?php echo $row['child_nric']; ?>"/>
<input type="hidden" name="teachernric" value="<?php echo $_SESSION['username']; ?>"/>
<input type="hidden" name="progcode" value="<?php echo $program; ?>"/>
<td><?php echo $row['child_nric']; ?></td>
<td>
<select name="attendance">
<option value="1" selected="<?php if($selected==1) echo "selected"; ?>">Present</option>
<option value="0" selected="<?php if($selected==0) echo "selected"; ?>">Absent</option>
</select>
</td>
<td> <input type="submit" name="submit" value="Submit"></td>
</tr>
<?php echo form_close();} ?>
</table>
<?php } ?>
</div>
The Controller part
public function Attendance($program = "")
{
$this->main_model->pagePermissions("Attendance");
if ($program == "") {
$this->load->view('Attendance');
} else {
$data['program'] = $program;
$this->load->view('Attendance', $data);
}
}
public function AttendanceSet()
{
$child_nric = $_POST['child_nric'];
$attendance = $_POST['attendance'];
$teachernric = $_POST['teachernric'];
$progcode = $_POST['progcode'];
$ispresent="No";
if($attendance==1)
{
$ispresent="Yes";
}
$this->load->model("Attendance_model");
$this->Attendance_model->insert($progcode, $childnric, $teachernric, $ispresent);
$this->load->view('Attendance');
}
The model part
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Attendance_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function insert($progcode, $childnric, $teachernric, $ispresent)
{
$sql = "INSERT INTO attendence (progcode, childnric, teachernric, ispresent ) VALUES (?,?,?,?) ";
$query = $this->db->query($sql, array($progcode, $childnric, $teachernric, $ispresent));
}
}
?>
try this:
<?php foreach($query->result_array() as $row){ ?>
<?php echo form_open('MainController/AttendanceSet');?>
<tr>
<input type="hidden" name="child_nric" value="<?php echo $row['child_nric']; ?>"/>
<input type="hidden" name="teachernric" value="<?php echo $_SESSION['username']; ?>"/>
<input type="hidden" name="progcode" value="<?php echo $program; ?>"/>
<td><?php echo $row['child_nric']; ?></td>
<td>
<select name="attendance">
<option value="1" selected="<?php if($selected==1) echo "selected"; ?>">Present</option>
<option value="0" selected="<?php if($selected==0) echo "selected"; ?>">Absent</option>
</select>
</td>
<td> <input type="submit" name="submit" value="Submit"></td>
</tr>
<?php echo form_close(); ?>
<?php } ?>
Both of the below statements should come outside the foreach loop
<?php echo form_open('MainController/AttendanceSet');?>
<?php echo form_close(); ?>// you need to close it
This is my Code :
Views :
<form method="post" action="<?php echo base_url(); ?>index.php/rbts/get_songs">
<div class="form-group">
<!-------------------------------------------------------- TOP Songs-------------------------------------------------------------->
<label class="col-sm-2 control-label">Top 1</label>
<div class="col-sm-10">
<select name="drptop_1" id="drptop_1" class="form-control m-b">
<?php
$n = 1;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<label class="col-sm-2 control-label">Top 2</label>
<div class="col-sm-10">
<select name="drptop_2" id="drptop_2" class="form-control m-b">
<?php
$n = 2;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 3</label>
<div class="col-sm-10">
<select name="drptop_3" id="drptop_3" class="form-control m-b">
<?php
$n = 3;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 4</label>
<div class="col-sm-10">
<select name="drptop_4" id="drptop_4" class="form-control m-b">
<?php
$n = 4;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 5</label>
<div class="col-sm-10">
<select name="drptop_5" id="drptop_5" class="form-control m-b">
<?php
$n = 5;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<!-------------------------------------------------------- New Songs-------------------------------------------------------------->
<hr height="5px" width="100%">
<label class="col-sm-2 control-label">New 1</label>
<div class="col-sm-10">
<select name="drptop_6" id="drptop_6" class="form-control m-b">
<?php
$n = 6;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 2</label>
<div class="col-sm-10">
<select name="drptop_7" id="drptop_7" class="form-control m-b">
<?php
$n = 7;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 3</label>
<div class="col-sm-10">
<select name="drptop_8" id="drptop_8" class="form-control m-b">
<?php
$n = 8;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 4</label>
<div class="col-sm-10">
<select name="drptop_9" id="drptop_9" class="form-control m-b">
<?php
$n = 9;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<label class="col-sm-2 control-label">New 5</label>
<div class="col-sm-10">
<select name="drptop_10" id="drptop_10" class="form-control m-b">
<?php
$n = 10;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
</div>
</div>
<div class="modal-footer">
Save
Close
</div>
</form>
controllers :
public function get_songs(){
$top1=$this->input->get_post('drptop1');
$top2=$this->input->get_post('drptop2');
$top3=$this->input->get_post('drptop3');
$top4=$this->input->get_post('drptop4');
$top5=$this->input->get_post('drptop5');
$new1=$this->input->get_post('drptop6');
$new2=$this->input->get_post('drptop7');
$new3=$this->input->get_post('drptop8');
$new4=$this->input->get_post('drptop9');
$new5=$this->input->get_post('drptop10');
die(var_dump($top1));
//$this ->rbt->update_all_songs($top1,$top2,$top3,$top4,$top5,$new1,$new2,$new3,$new4,$new5);
}
And after that it always says bool(false). =.=
Your are getting bool(false) because there is no value in $top1.
Secondly, the input name in the form is differnt from the variable name you are using to fetch the value.
Example:
<select name="drptop_1" id="drptop_1" class="form-control m-b"></select>
AND
$top1=$this->input->get_post('drptop1');
Try, using same input name name="drptop_1" and php variable name get_post('drptop1')
Hope this is helpful.
Please do I hide this form (form.php) if this condition is TRUE. That is, I don't want the entire form to show if this condition is TRUE. Thanks.
Condition: if ($session_id == $query1){
form.php
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/>
</form>
<?php
if ($session_id != $query1){
?>
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/> </div>";
</form>
<?php
}else{
}
?>
It would be easier to add a class to your form.
<form action="tmembers.php" method="post" <?php if ($session_id == $query1){ echo 'class="hide"'; ?> >
And then use the following css:
.hide{
display: none;
}
If you DON'T want to show the form when this condition is true you need to change the operator
So this below:
if ($session_id == $query1) //EQUAL
Becomes
if ($session_id != $query1) //NOT EQUAL
What about put the php condition on top of the form so if it's not true php won't render the form at all.
PHP
<?php if ($session_id != $query1){ ?>
<form action="tmembers.php" method="post">
<input type="hidden' value='<?php echo $_GET['id']; ?>' name="id"/></br>
<select multiple="true" name="members[]" val id="member" class="">
<?php while($record = $stmt->fetch()) : ?>
<option value="<?php echo $record['id'] ; ?>"> <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?> </option>
<?php endwhile; ?>
</select></br>
<input type="submit" value="Send Invite" name="invite" class=""/> </div>";
</form>
<?php } ?>
If the condition isn't on page load, you can do some Js :
/*Some JS event if needed before*/
if(<?php $session_id != $query1 ?>){
$('form').hide();
}