Multiple form_open with button - forms

I have several buttons which should make different things.
To one, a button should make one entry in table 1 and another in table 2.
But if I do it as in the code below.
He always makes an entry in Table 1.
How can I assign the respective buttons?
<?php echo form_open('Karte/insert_artikel'); ?>
<?php echo form_open('Karte/insert_trade'); ?>
<input type="hidden" name="add_karte_id" value="<?php echo $edition_views['tb_karte_id']; ?>">
<input type="hidden" name="add_karten_stats_id" value="<?php echo $edition_views['tb_karte_karten_stats']; ?>">
<input type="hidden" name="add_karte_sprache" value="<?php echo $edition_views['tb_sprache_id']; ?>">
<input type="hidden" name="add_karte_qualitat" value="<?php echo $edition_views['tb_qualitat_id']; ?>">
<input type="hidden" name="add_karte_auflage" value="<?php echo $edition_views['tb_auflage_id']; ?>">
<input type="hidden" name="add_karte_edition_stats" value="<?php echo $edition_views['tb_karte_edition_stats']; ?>">
<input type="hidden" name="add_karte_datum" value="<?php $date = date_create($edition_views['tb_karte_datum']); echo date_format($date,"Y-m-d H:i:s");?>">
<tr>
<td><?php echo $edition_views['tb_edition_kurzel']; ?>-<?php echo $edition_views['tb_sprache_kurzel']; ?><?php echo $edition_views['tb_edition_stats_nummer']; ?></td>
<td><button class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $edition_views['tb_qualitat_name']; ?>"><img src="<?php echo base_url(); ?>assets/images/site/qualitat/<?php echo $edition_views['tb_qualitat_id']; ?>.png"/> <?php echo $edition_views['tb_qualitat_short']; ?></button></td>
<td><button class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $edition_views['tb_rare_name']; ?>"><?php echo $edition_views['tb_rare_short']; ?></button></td>
<td><?php echo $edition_views['tb_auflage_name_de']; ?></td>
<td><?php $date = date_create($edition_views['tb_karte_datum']); echo date_format($date,"d.m.Y");?></td>
<td><?php echo str_pad($edition_views['tb_karte_anzahl'], 2, '0', STR_PAD_LEFT); ?></td>
<td>
<?php
switch($edition_views['tb_karte_versuche'])
{
case (0):
echo "<FONT COLOR='#000000'>".$edition_views['tb_karte_versuche']."</FONT>";
break;
case (1):
echo "<strong><FONT COLOR='#D7DF01'>".$edition_views['tb_karte_versuche']."</FONT></strong>";
break;
case (2):
echo "<strong><FONT COLOR='#298A08'>".$edition_views['tb_karte_versuche']."</FONT></strong>";
break;
case (3):
echo "<strong><FONT COLOR='#DF0101'>".$edition_views['tb_karte_versuche']."</FONT></strong>";
break;
}
?>
</td>
<td>
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="add_karte_menge[<?php echo $edition_views['tb_karte_id']; ?>]"><span class="glyphicon glyphicon-minus"></span></button>
</span>
<input type="text" name="add_karte_menge[<?php echo $edition_views['tb_karte_id']; ?>]" class="form-control input-number" value="1" min="1" max="<?php echo $edition_views['tb_karte_anzahl']; ?>">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="add_karte_menge[<?php echo $edition_views['tb_karte_id']; ?>]"><span class="glyphicon glyphicon-plus"></span></button>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Verkauf Hinzufügen"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tausch Hinzufügen"><span class="glyphicon glyphicon-transfer" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Zur Sammlung"><span class="glyphicon glyphicon-gift" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Bearbeiten"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Verloren"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></button>
</span>
</div>
</td>
</tr>
<?php echo form_close(); ?>
<?php echo form_close(); ?>

You cannot nest forms.
You have a couple of options here:
A) Have separate forms (not nested) with a button in each form. Each form would be directed to its own controller which redirects back to the same controller or view afterwards
B) Have a single form and a single controller, but attach a different name to each button - i.e.
<form action="/some-controller" method="post">
<button name="do_something" value="1">Do Something</button>
<button name="do_something_different" value="1">Do Something Different</button>
</form>
Then in your controller you can look for the posted variables do_something and do_something_different to determine which button the user clicked and determine your action accordingly.

Related

Why modal bootstrap on table data doesn't showing / fetching match data when popup?

Please check this image
I try to fetching data on every table data using modal bootstrap, but when i click every modal button it's just showing last table data in form of my popup modal. I want the data is per in the form on modal bootstrap. I am using CodeIgniter. Please help me, thanks. GBU
HERE IS MY CODE:
<table class="table table-bordered table-striped nowrap text-gray-900" id="dataTable" width="100%" style="font-size: 13px;" cellspacing="0">
<thead>
<tr class="table-success">
<th>ID</th>
<th>NOMOR</th>
<th>KODE</th>
<th>TINDAKAN</th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
<?php
foreach ($prosedur_rehab as $rehab) {
?>
<tr>
<td><?= $rehab->ID; ?></td>
<td><?= $rehab->NOMOR; ?></td>
<td><?= $rehab->KODE; ?></td>
<td><?= $rehab->TINDAKAN; ?></td>
<td>
<button type="button" class="btn btn-sm btn-info" data-toggle="modal" data-target="#perawat<?php echo $rehab->ID;?> ">
<i class="fas fa-user-nurse"></i>
</button>
<div class="modal fade" id="perawat<?php echo $rehab->ID;?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" >
<div class="modal-dialog modal-lg" >
<div class="modal-content">
<div class="modal-header" style="background-color:#5bc0de">
<h5 class="modal-title" id="exampleModalLabel">Kelola Rawat Jalan (Diisi Oleh Perawat)</h5>
<button type="button" class="btn-danger" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="<?php echo base_url().'dokter/kunjungan/kirimlaprajal'?>">
<div class="form-group">
<!-- <label for="exampleInputEmail1">ID</label> -->
<select name="" class="form-control">
<option>-- CARI --</option>
<?php foreach ($prosedur_rehab as $rehab):?>
<option value="<?php echo $rehab->ID?>"><?php echo $rehab->ID?> || <?php echo $rehab->NORM?></option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<label for="exampleInputEmail1">ID Prosedur</label>
<input type="text" name="ID" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->ID; ?>">
</div>
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">No. Pendaftaran</label>
<input type="text" name="NOMOR" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->NOMOR; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Kode</label>
<input type="text" name="KODE" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->KODE; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Tindakan</label>
<input type="text" name="TINDAKAN" class="form-control" id="exampleInputEmail1" autocomplete="off" value="<?php echo $rehab->TINDAKAN; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Tanggal</label>
<input type="datetime-local" name="TANGGAL" class="form-control" id="exampleInputEmail1" required autocomplete="off" placeholder="" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Instrumen Uji Fungsi</label>
<input type="text" name="PROGRAM" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Hasil</label>
<input type="text" name="HASIL" class="form-control" id="exampleInputEmail1" required autocomplete="off" placeholder="" value="">
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">Kesimpulan</label>
<input type="text" name="KESIMPULAN" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Rekomendasi</label>
<input type="text" name="REKOMENDASI" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Oleh</label>
<input type="text" name="OLEH" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="<?php echo $session_user->nip ;?>" readonly>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Status</label>
<input type="text" name="STATUS" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
</div>
</div>
<button type="submit" name="simpen" class="btn btn-info float-right"><i class="fas fa-save"> </i> Simpan</button>
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>NOMOR</th>
<th>KODE</th>
<th>TINDAKAN</th>
</tr>
</tfoot>
</table>
i tried your code and it works perfectly, Check your $rehave->ID value maybe it doesn't have value or have invalid value, or check your modal plugins
The problem is i was used same foreach in select option . I was forgot if i 've been using first foreach to displaying table data and i used it again in form.
Don't using same foreach in form, delete or change this:
<select name="" class="form-control">
<option>-- CARI --</option>
<?php foreach ($prosedur_rehab as $rehab):?>
<option value="<?php echo $rehab->ID?>"><?php echo $rehab->ID?> || <?php echo $rehab->NORM?></option>
<?php endforeach ?>
</select>

how to manipulate with codeigniter

How I get my data array from view? and how to insert in my database?
my view, I try much code but still an error, sorry about my question and my bad English
<form role="form" action="<?php echo base_url().'potongan/validasi'?>" action="GET">
<div class="box-body">
<div class="box-header with-border">
<div class="row">
<div class="col-xs-3">
<label >NIM</label>
<input type="text" class="form-control" name="nim" id="nim" placeholder="NIM" value="<?php echo $nime ?>" readonly>
</div>
<div class="col-xs-3">
<label >Nama Mahasiswa</label>
<input type="text" class="form-control" name="namamhs" placeholder="Nama Mahasiswa" value="<?php echo $nim[0]->namamhs ?>" disabled>
</div>
<div class="col-xs-3">
<label >Jurusan</label>
<input type="text" class="form-control" name="jurusan" placeholder="Jurusan" value="<?php echo $nim[0]->jurusan ?>" disabled>
</div>
</div>
<br>
<div class="form-group">
<label >Kode Beasiswa</label>
<input type="text" class="form-control " name="kdbeasiswa" value="<?php echo $kdbeasiswa ?>" readonly>
</div>
<div class="form-group">
<label >Keterangan</label>
<input type="text" class="form-control " name="keterangan" value="<?php echo $keterangan ?>" readonly>
</div>
<div>
<table class="table table-bordered table-striped">
<tr>
<th></th>
<th>Kode</th>
<th>Deskripsi</th>
<th>Tahun Akademik</th>
<th>semester</th>
<th>Tagihan</th>
<th>Beasiswa</th>
<th>Terbayar</th>
<th>Potongan</th>
</tr>
<?php foreach ($nim as $n): ?>
<tr>
<td>
<input type="hidden" class="form-control " name="id[]" value="<?php echo $n->thakad.$n->smtakad.$n->kdkeu; ?>" maxlength="3" >
</td>
<td><input type="hidden" class="form-control " name="kdkeu[]" value="<?php echo $n->kdkeu; ?>" maxlength="3" ><?php echo $n->kdkeu; ?></td>
<td><?php echo $n->deskeu; ?></td>
<td><input type="hidden" class="form-control " name="thakad[]" value="<?php echo $n->thakad; ?>" maxlength="3" ><?php echo $n->thakad; ?></td>
<td><input type="hidden" class="form-control " name="smtakad[]" value="<?php echo $n->smtakad; ?>" maxlength="3" ><?php echo $n->smtakad_view; ?></td>
<td><?php echo $n->tagihan; ?></td>
<td><?php echo $n->beasiswa; ?></td>
<td><?php echo $n->terbayar; ?></td>
<td>
<input type="text" class="form-control " name="prosentase_bea[]" value="<?php echo $n->potongan; ?>" maxlength="3">
</td>
</tr>
<?php endforeach ?>
</table>
</div>
</div>
<br>
<button class="btn btn-info" style="float: right;">submit</button>
</div>
<!-- /.box-body -->
</form>
my controller looks like this when I submit no data insert to the database and error like
Filename: C:/xampp/htdocs/tagihan/system/database/DB_query_builder.php
Line Number: 1498
$data = array();
$count = count($this->input->post('device'));
for($i=0; $i<$count; $i++) {
$data[] = array(
$thakad= $this->input->get('thakad'),
$smtakad= $this->input->get('smtakad'),
$kb = $this->input->get('kdbeasiswa'),
$kk = $this->input->get('kdkeu'),
$nim= $this->input->get('nim'),
$pb = $this->input->get('prosentase_bea'),
$status = 1,
$user = $this->session->userdata('username'),
$kt = $this->input->get('keterangan'),
$curentDate = date("Y-m-d"));
}
$this->db->insert_batch('keu_beasiswapermhs',$data);
redirect('http://localhost/tagihan/potongan');
Make a habit using the proper MVC
VIEW
<form action="URL" method="post">
</form>
CONTROLLER
$this->model->function_name();
redirect('URL');
MODEL
function function_name(){
$dataArr = array(
'field_name'=>$this->input->post('form_input_name'),
);
$this->db->INSERT('tbl_name',$dataArr);
}
You have fields like "namamhs" and "jurusan" that are not being put into the db.
You do not need for or while loops to insert data
You are not assigning what fields in your db each posted item goes to. Your controller has no idea where each value should be inserted. Do not use get, you should use post. Here is an example for your controller you can adapt to your form:
$data = [
'url' => $this->input->post('url'),
'name' => $this->input->post('name'),
'genre' => $this->input->post('genre'),
'counter' => $this->input->post('counter'),
'type' => $this->input->post('type')
];
where 'url' is a field in your db that you are putting $this->input->post('url') into.
Next you check the values:
$this->form_validation->set_rules('url', 'url', 'required|trim');
$this->form_validation->set_rules('name', 'Name', 'required|trim|callback_trims');
$this->form_validation->set_rules('genre', 'Genre', 'required|trim');
$this->form_validation->set_rules('counter', 'Counter', 'numeric');
$this->form_validation->set_rules('type', 'Type', 'required|min_length[3]');
If the values pass the validation, inserting is simple
if( $this->form_validation->run() == FALSE) {
echo validation_errors();
}else
{
$this->db->insert('music', $data);
}
You do not need batch insert. Just use insert
Your $data array is empty...always check if array not empty before insert batch...that cause error DB_query_builder.php Line Number: 1498

Form button not working properly in IE11(and probably more)

I've made page where you can get an overview over invoices.
Everything works great, except from with Internet Explorer...
When I click the see order button, nothing happens in IE.
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" onSubmit="window.location.reload()">
<tr><td><?php
$Date = $row['date'];
echo $Date;
?></td><td><?php echo $row['autoid'];?></td>
<input name='implodehideu' type='hidden' value='<?php echo $row['implodeuke'];?>;'>
<input name='implodehidew' type='hidden' value='<?php echo $row['implodehelg'];?>;'>
<input name='personid' type='hidden' value='<?php echo $row['primeid'];?>;'>
<input name='invoiceid' type='hidden' value='<?php echo $row['autoid'];?>'>
<td><input type="submit" name="seeorder" id="submit" value="Order overview"></td>
<td><?php echo $row['firstname'] . " " . $row['surname'];?></td>
<td><?php echo $row['amount'];?></td>
<?php
if ($paidboolean)
echo "<td bgcolor='#3AA849'>YES</td>";
else
echo "<td bgcolor='#e94336'>NO</td>";
if (!$paidboolean) {
?>
<td><input type="submit" name="confirm" id="submit" value="Mark as paid"></td>
<?php
} else {
?>
<td><input type="submit" name="notconfirm" id="submit" value="Mark as not paid"></td>
<?php
}
?>
<td><input type="submit" name="slett" id="submit" value="Slett"></td>
</form>
<?php
if (isset($_POST['seeorder'])) {
.....Things to show up
}
Try to set the id argument of the submit button to something else than 'submit'. That helped me with the same problem.
<input type="submit" name="slett" id="btnSubmit" value="Slett" />

HTML/PHP Form Formatting Error

im new so don't go to hard on me here. I'm trying to make this registration form into two rows but every time i try it does not post all the values from both rows of the form, just the first.
http://i.stack.imgur.com/TSnjl.png
<table width="990" border="0">
<tr>
<td width="486" height="221"><form id='register' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Register</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div class='short_explanation'>* required fields</div>
<input type='text' class='spmhidip' name='<?php echo $fgmembersite->GetSpamTrapInputName(); ?>' />
<div class="container"><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span>
<label for='name' >Your First Name*: </label>
<br/>
<input type='text' name='name' id='name' value='<?php echo $fgmembersite->SafeDisplay('name') ?>' maxlength="50" />
<br/>
</div>
<div class='container'>
<label for='lastname' >Your Last Name*: </label>
<br/>
<input type='text' name='lastname' id='lastname' value='<?php echo $fgmembersite->SafeDisplay('lastname') ?>' maxlength="50" />
<br/>
<span id='register_name_errorloc' class='error'></span> </div>
<div class='container'>
<label for='email' >Email Address*:</label>
<br/>
<input type='text' name='email' id='email' value='<?php echo $fgmembersite->SafeDisplay('email') ?>' maxlength="50" />
<br/>
<span id='register_email_errorloc' class='error'></span> </div>
<div class='container'>
<label for='username' >UserName*:</label><br/>
<input type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
<span id='register_username_errorloc' class='error'></span>
<br/>
<span id='register_username_errorloc' class='error'></span> </div>
<div class='container' style='height:80px;'>
<label for='password' >Password*:</label>
<br/>
<div class='pwdwidgetdiv' id='thepwddiv' ></div>
<noscript>
<input type='password' name='password' id='password' maxlength="50" />
</noscript>
<div id='register_password_errorloc' class='error' style='clear:both'></div>
</div>
<input type='text' class='spmhidip' name='<?php echo $fgmembersite->GetSpamTrapInputName(); ?>2' />
<div class="container">
<p><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span>
<label for='phonenumber' >Phone Number: </label>
<br/>
<input type='text' name='phonenumber' id='phonenumber' value='<?php echo $fgmembersite->SafeDisplay('phonenumber') ?>' maxlength="15" />
<br/>
</p>
</div>
<div class='container'>
<label for='address' >Address: </label>
<br/>
<input type='text' name='address' id='address' value='<?php echo $fgmembersite->SafeDisplay('address') ?>' maxlength="40" />
<br/>
</div>
<div class='container'>
<label for='city' >City:</label>
<br/>
<input type='text' name='city' id='city'value='<?php echo $fgmembersite->SafeDisplay('city') ?>' maxlength="20">
<br/>
</div>
<div class='container'>
<label for='State' >State:</label>
<br/>
<input type='text' name='state' id='state' value='<?php echo $fgmembersite->SafeDisplay('state') ?>' maxlength="2" />
</div>
<div class='container'>
<label for='State' >Country:</label>
<br/>
<input type='text' name='country' id='country' value='<?php echo $fgmembersite->SafeDisplay('country') ?>' maxlength="3" />
<br/>
</div>
<div class='container' style='height:80px;'>
<p>
<label for='zip' >ZipCode:</label>
<br/>
<input type='text' name='zipcode' id='zipcode' value='<?php echo $fgmembersite->SafeDisplay('lastname') ?>' maxlength="5" />
</p>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
<p> </p>
</div>
</fieldset>
</form></td>
<td width="494" valign="top"><h2> </h2></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
I think possible the error is in the way u use double quotes and single quotes.
value='<?php echo $fgmembersite->SafeDisplay('username') ?>'
should be changed to
value="<?php echo $fgmembersite->SafeDisplay('username') ?>"
Could you report back to me what happens if you do this in all the cases

mark the input box red if the required field of a form is not filled

i'm using Codeigniter. i have a form which takes information about users. What i want to do is to check whether all the required fields are filled up or not.If any of the required fields is not filled up i want mark that input box red. Right now my codes only check if the required fields are filled up or not. if not it says the "field is required" but how to mark input box.I'm a bit confused how to do this thing.Can somebody help me out with a little hint. Thanks.
the view for my form:
<?php
$attributes = array('class' => '', 'id' => '');
echo form_open('register', $attributes); ?>
<p>
<label for="name">Name <span class="required">*</span></label>
<?php echo form_error('name'); ?>
<br /><input id="name" type="text" name="name" value="<?php
echo set_value('name'); ?>"
</p>
<p>
<label for="username">Username <span class="required">*</span></label>
<?php echo form_error('username'); ?>
<br /><input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>"
</p>
<p>
<label for="password">Password <span class="required">*</span></label>
<?php echo form_error('password'); ?>
<br /><input id="password" type="password" name="password" value="<?php echo set_value('password'); ?>"
</p>
<p>
<label for="email">Email <span class="required">*</span></label>
<?php echo form_error('email'); ?>
<br /><input id="email" type="text" name="email" value="<?php echo set_value('email'); ?>"
</p>
<p>
<label for="phone">Phone</label>
<?php echo form_error('phone'); ?>
<br /><input id="phone" type="text" name="phone" value="<?php echo set_value('phone'); ?>"
</p>
</p>
<p>
<input type="submit" value="Submit information" class="formbutton"/>
</p>
<?php echo form_close(); ?>
Generally, I'd recommend creating an textInputError class where you adjust the input style, and then apply it based on the existence of the error...
class="<?php echo (form_error('username') ? 'textInputError' : '') ?>"
in place in the input element...
<input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>" class="<?php echo (form_error('username') ? 'textInputError' : '') ?>">