jquery + php and mysql text boxes HELP? - php

I am trying to use a jquery to have text boxes and little pluses and minuses to add and delete them when required. It displays the data from MySQL but you can't delete them and you can only add them
Here is a link to a webpage i am using
http://adamlisik.co.uk/epq2/models/certificate.php?certid=250631166
I want to find a way that the text boxes that are displayed with the data from db can be deleted
<script type="text/javascript">
$(document).ready(function(){
// tworzymy zmienną i, wykorzystamy ją do identyfikowania wierszy
// ustawiamy jej wartość 2, ponieważ jeden wiersz jest już w tabeli
var i = 2;
// tworzymy zmienną szablonWiersza i wczytujemy do niej szablon z textarea #szablon
var szablonWiersza = jQuery.format($("#szablon").val());
// tworzymy funkcję, która dodaje szablon do właściwej tabeli
function dodajWiersz() {
var ii = i++;
// dodajemy wiersz do właściwej tabeli
$(szablonWiersza(ii)).appendTo("#listaOsob tbody");
// Nowy wiersz jest już widoczny.
// Każdy element nowego wiersza posiada swoje id
// tr na id: wiersz_2, ikona minus ma id: usunOsobe_2
// Do nowo dodanej ikony - dodajmy zdarzenie.
// W momencie kliknięcia minusa, wiersz zostanie usunięty.
$("#usunOsobe_" + ii).click(function(){
$("#wiersz_" + ii).remove();
});
}
// do przycisku #dodajOsobe dodajemy zdarzenie,
// kliknięcie na przycisk plus wywoła fukcję dodajWiersz
$("#dodajOsobe").click(dodajWiersz);
});
</script>
<h1>Sixth form baccaluraureate</h1>
<div id="content">
<textarea id="szablon" style="display:none;" cols="1" rows="1">
<tr id="wiersz_{0}">
<td><input type="text" name="name[]" ></td>
<td><input type="text" name="hours[]"></td>
<td><input type="hidden" name="certificate_id[]"value="<?php echo $table2[0][2]; ?>">
<td><img src="http://antczak.org/source/dynamic_forms/12.png" id="usunOsobe_{0}" alt="usun"></td>
</tr>
</textarea>
<!-- Właściwa tabela -->
<h4>activities form</h4>
<form action="update_certificate.php" method="post">
<!-- do not delete student is!!!! because we need it in confirm_cert.php-->
<input type="hidden" name="student_id" value="<?php echo $row[0] ?>" /> <br />
<input type="hidden" name="student_id2" value="<?php echo $row[3] ?>" /> <br />
<input type="hidden" name="certificate_number" value="<?php echo $certificate_name; ?>" />
<br/>
<table id="listaOsob">
<thead>
<tr>
<th>Activity name</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$a=0;
while($a<sizeof($table2)){
echo "<tr><td><input type='text' name='name[]' value='".$table2[$a][0]."'></td>";
echo "<td><input type='text' name='hours[]' value='".$table2[$a][1]."'></td>";
echo "<td><input type='hidden' name='certificate_id[]' value='".$table2[$a][2]."'></td>";
#echo $a;
if ($a==0){
echo "<td><img src='../view/11.png' id='dodajOsobe' alt='dodaj'></td></tr>";
}else{
echo "<td><img src='../view/12.png' id='usunOsobe_{0}' alt='usun'></td></tr>";
}
$a++;
}
?>
</tr>
</tbody>
</table>
<input type="submit" value="Submit" />
</form>
</div>

Perhaps you could use the jQuery .remove() function.
http://api.jquery.com/remove/

Related

How to make a dynamic form in Codeigniter

I want to ask something as a Codeigniter newbie.
I want make a dynamic form in CI, if I want increase a form, I can click " Increase" then the form will increase at the bottomw, and if click "Increase" too many times I can click "Delete" then the form will decrease..
I made it with the dynamic form, but my problem arises when I want to save it to the SQL database.
My code is like this :
tambah_material.php
<div id="isi">
<h1>Material Order</h1><br />
<div class="submitButton">List Material Order</div>
<br><br><br><br><table width="100%">
<form method="post" id="myfrm" action="<?php echo base_url(); ?>index.php/adminweb/simpanmaterial">
<tr><td width="200">Project Name</td><td width="10" align="center">:</td><td><input type="text" class="input" name="nama_lengkap" size="100" /></td></tr>
<tr><td width="200">Project Status</td><td width="10" align="center">:</td><td>
<select name="nama" class="input">
<option value="Under Project Implementation" selected="selected">Under Project Implementation</option><option value="Under Warranty">Under Warranty</option>
<option value="Project Warranty">Project Warranty</option><option value="Out of Warranty">Out of Warranty</option>
</select></td></tr>
<tr><td width="200">Site/Hop Name</td><td width="10" align="center">:</td><td><input type="text" class="input" name="nim" size="50" /></td></tr>
<tr><td width="200">Material Description</td><td width="10" align="center">:</td><td>
<script type="text/javascript">
$(document).ready(function() {
var nomor = 0;
var status="";
$(".tambah").click(function(){
nomor ++;
$('#konten').append(
'<tr class="baris">'
+ '<input name="nomor[]" value="'+ nomor +'" type="hidden"></td>'
+ '<td><input name="tempat_'+ nomor +'" type="text" size="40"></td>'
+ '<td><input name="sn_'+ nomor +'" type="text" size="60"></td>'
+ '<td><input type="button" id="hapus" value="Hapus"></td></tr>'
);
});
$("#hapus").live('click', function () {
$(this).parents(".baris").remove();
});
$("#myfrm").validate({
debug: false,
rules: {
},
messages: {
},
});
});
function tampilTabel()
{
if(status=="")
{
$('#tabel').slideDown();
status="1";
}
else
{
$('#tabel').slideUp();
status="";
}
}
</script>
<a class="tambah" style="cursor:pointer; padding:6px; border:1px solid #000; background-color:#FF9900; color:#000000;">Tambah Form</a>
<br><br>
<tr><td></td><td></td><td>Nama Material :
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
Serial Number :</td>
</tr>
<tr id="konten"><td></td><td>
<tr><td width="150">Reason/Suspect Problem</td><td width="10">:</td><td>
<select name="jk" class="input">
<option value="Interference" selected="selected">Interference</option><option value="Lightning Strike">Lightning Strike</option>
<option value="Leakage Shelter">Leakage Shelter</option><option value="Replace Broken One">Replace Broken One</option>
<option value="Borrow">Borrow</option><option value="Others">Others</option>
</select>
</td></tr>
<tr><td width="200">Returned to RWH</td><td width="10" align="center">:</td><td><input type="text" class="input" name="alamat" size="70"/></td></tr>
<tr><td width="200">Quantity</td><td width="10" align="center">:</td><td><input type="text" class="input" name="jml" size="70"/></td></tr>
<tr><td width="200">Status</td><td width="10" align="center">:</td><td>
<select name="status" class="input">
<option value="yes" selected="selected">Yes</option><option value="no">No</option></select>
</select>
</td></tr>
<tr><td width="200"></td><td width="10" align="center"></td><td><input type="submit" value="Simpan Data" class="input" /> <input type="reset" value="Hapus" class="input" /></td></tr>
</form>
</table>
</div>
adminweb.php (controller)
function simpanmaterial()
{
$data=array();
$data2=array();
$session=isset($_SESSION['username_belajar']) ? $_SESSION['username_belajar']:'';
if($session!=""){
$pecah=explode("|",$session);
$data["username"]=$pecah[0];
$data["nama"]=$pecah[1];
$data["status"]=$pecah[2];
$data['scriptmce'] = $this->scripttiny_mce();
if($data["status"]=="admin"){
$tgl = " %Y-%m-%d";
$time = time();
$in["nama"]=$this->input->post('nama');
$in["nim"]=$this->input->post('nim');
$in["nama_lengkap"]=$this->input->post('nama_lengkap');
$in["alamat"]=$this->input->post('alamat');
$in["jk"]=$this->input->post('jk');
$in["jml"]=$this->input->post('jml');
$in["status"]=$this->input->post('status');
$in["tempat_1"]=$this->input->post('tempat_1');
$in["tempat_2"]=$this->input->post('tempat_2');
$in["tempat_3"]=$this->input->post('tempat_3');
$in["tempat_4"]=$this->input->post('tempat_4');
$in["sn_1"]=$this->input->post('sn_1');
$in["sn_2"]=$this->input->post('sn_2');
$in["sn_3"]=$this->input->post('sn_3');
$in["sn_4"]=$this->input->post('sn_4');
$in["tanggal"] = mdate($tgl,$time);
$in["penulis"] = $data["username"];
if($in["nama_lengkap"]=="" || $in["nim"]=="" || $in["alamat"]=="")
{
echo "Data masih kosong..!!!";
}
else{
$this->Admin_model->Simpan_Artikel("tbl_mahasiswa",$in);
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/adminweb/insbaru'>";
}
}
else{
?>
<script type="text/javascript" language="javascript">
alert("Anda tidak berhak masuk ke Control Panel Admin...!!!");
</script>
<?php
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/'>";
}
}
else{
?>
<script type="text/javascript" language="javascript">
alert("Anda belum Log In...!!!\nAnda harus Log In untuk mengakses halaman ini...!!!");
</script>
<?php
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/'>";
}
}
thanks for your help
Best Regards,
Karisma
For making your code Dynamic you can grab a existing MY_MODEL from github,and if you want to make your design responsive use Bootstrap.

How to capture different values for the items belong to the same group

I have a table to display Addon items from database.
The user must check the checkbox for the first two items namely: gps and babyseat.
So the deposit and priceperday are captured inside add_item[] of the checkbox.
But the third item which is Driver, there's no deposit or priceperday but price per hour.
So I gave out two radio buttons namely: one for per8thhour rate and the other one for per16thhour rate.
The problem is it captures both rate but I only want either one value of the radio button to be recorded.
Here's the table:
<table border="1" style="border-collapse: collapse;margin-top: 20px;">
<tr>
<th>AddOns</th>
<th>Deposit</th>
<th>PricePerDay</th>
<th>Price per 8th Hour</th>
<th>Price per 16th Hour</th>
<th></th>
</tr>
<?php
while($row_addon=mysql_fetch_array($result_addon))
{
$add_on_id=$row_addon['addOns_id'];
$add_on=$row_addon['addOns'];
$deposit=$row_addon['Deposit'];
$ppd=$row_addon['PricePerDay'];
$pp8=$row_addon['PricePer8thHour'];
$pp16=$row_addon['PricePer16thHour'];
$status=$row_addon['status'];
?>
<tr>
<td><input type="hidden" name="add_name" value=""><?php echo $add_on;?></td>
<td><input type="hidden" name="add_on"><?php echo $deposit;?></td>
<?php
if(isset($add_on)&&($add_on!=='Driver'))
{
?>
<td><input type="hidden" name="add_on"><?php echo $ppd;?></td>
<td><input type="hidden" name="add_on"><?php echo $pp8;?></td>
<td><input type="hidden" name="add_on"><?php echo $pp16;?></td>
<?php
}
else
{
?>
<td><input type="hidden" name="add_on"><?php echo $ppd;?></td>
<td><input type="radio" name="add_on"><?php echo $pp8;?></td>
<td><input type="radio" name="add_on"><?php echo $pp16;?></td>
<?php
}
?>
<td><input type="checkbox" name="add_item[]" value="<?php echo $add_on_id;?>"/></td>
</tr>
<?php
}
?>
<input type="hidden" name="submit_add">
<tr><td colspan="6"></td></tr>
</table>
I'm recording the value like this:
if(isset($_POST['submit_add']))
{
$add_item=$_POST['add_item'];
echo $add_item_1=implode(',',$add_item);
}
How do I make it possible to catch only the value selected by user for the item driver.
At the same time group them all under one name which is addon so that I can store them as one group in session later?
FULL FORM:
<form action="" method="POST">
<?php
//display pickup location
mysql_select_db($database_bumi_conn, $bumi_conn);
$q="SELECT * FROM tbl_pickup_location WHERE pickup_id='$location'";
$r=mysql_query($q);
$row_show= mysql_fetch_array($r);
?>
<input type="hidden" name="lo" value="<?php echo $location_name=$row_show['pickup_location'];?>">
<?php
echo 'Pickup Location :'.$location_name=$row_show['pickup_location'].'<br/>';
//display dropoff location
mysql_select_db($database_bumi_conn, $bumi_conn);
$q_1="SELECT * FROM tbl_dropoff WHERE dropoff_id='$d_location'";
$r_1=mysql_query($q_1);
$row_show_1= mysql_fetch_array($r_1);
?>
<input type="hidden" name="d_lo" value="<?php echo $location_name_1=$row_show_1['dropoff_location'];?>">
<?php
echo 'Return Location : '.$location_name_1=$row_show_1['dropoff_location'].'<br/>';
?>
<input type="hidden" name="val_1" value="<?php echo $date_value; ?>"/>
<?php
echo 'Pickup date : '.$date_value.'<br/>';
?>
<input type="hidden" name="val_2" value="<?php echo $date_value_2; ?>"/>
<?php
echo 'Return date : '.$date_value_2.'<br/>';
//$days=0;
$days=$diff->format("%a Days");
echo 'Total Rental for : '.$days.'<br/>';
//echo"hdssssssssssssfviodrhfvuhgudfhghdfhijswdjiahsdhsndjfhzsnhio";
$total_days=(int)$days;
?>
<input type="hidden" name="t_days" value="<?php echo $total_days; ?>"/>
<?php
include'calculation.php';
?>
<input type="hidden" name="sum" value="<?php echo $sum;?>">
<?php
mysql_select_db($database_bumi_conn, $bumi_conn);
$q_addon="SELECT * FROM tbl_addons";
$result_addon= mysql_query($q_addon)or die(mysql_error());
echo "<hr width=540>";
?>
<table border="1" style="border-collapse: collapse;margin-top: 20px;">
<tr><th>AddOns</th><th>Deposit</th><th>PricePerDay</th><th>Price per 8th Hour</th><th>Price per 16th Hour</th><th></th></tr>
<?php
while($row_addon=mysql_fetch_array($result_addon))
{
$add_on_id=$row_addon['addOns_id'];
$add_on=$row_addon['addOns'];
$deposit=$row_addon['Deposit'];
$ppd=$row_addon['PricePerDay'];
$pp8=$row_addon['PricePer8thHour'];
$pp16=$row_addon['PricePer16thHour'];
$status=$row_addon['status'];
?>
<tr>
<td><input type="hidden" name="add_name" value=""><?php echo $add_on;?></td>
<td><input type="hidden" name="add_item[]"><?php echo $deposit;?></td>
<td><input type="hidden" name="add_item[]"><?php echo $ppd;?></td>
<td><input type="radio" name="add_item[]" value="eight"><?php echo $pp8;?></td>
<td><input type="radio" name="add_item[]" value="six"><?php echo $pp16;?></td>
<td><input type="checkbox" name="add_item[]" value="<?php echo $add_on_id;?>"/></td>
</tr>
<?php
}
?>
<input type="hidden" name="submit_add">
<tr><td colspan="6"></td></tr>
</table>
<input type="image" src="submit.png" name="submit" value="submit" onclick="return confirm('Do you really want to proceed to checkout?');"href="checkout.php" style="padding-left:20px;" title="Add to cart"/>
</form>
To select one radio button at once, you have to give the all radio button's name same.
Otherwise you have to use javascript/jquery to deselect others when one is selected.
if you give all radio button name same, then when you post it will just post the value of the radio which is selected. You can get it by $_POST['radio_name'] .
Here it is $_POST['add_item'] .
If you are interested to use jquery, you can do that in this way
<script>
$(document).ready(function() {
$('input:radio').click(function(event) {
$('input:radio').not(this).attr('checked', false);
$(this).attr('checked', true);
});
});
</script>

php mysql and javascript conflict in loading

I'm unable to retrieve from my phpMyAdmin database using php code while i load the map api which uses javascript.
It only load the map javascript. I have some data stored in my database. Any help is appreciated. Thanks!
The end result must be both(my database data & the map api) able to load at the same time onto the screen.
<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<th>Routes Available</th>
<th>Map Direction</th>
<th>Preferred Routes</th>
</tr>
<tr>
<td><div id="sidebar">
<form name="form1" method="get" action="" onSubmit = "getDirections( this.from.value, this.to.value, this.mode.value ); return false;">
<p>
<label style="width:50px;display:inline-block;">From:</label>
<input type="text" size="34" name="from" value=""/>
</p>
<p>
<label style="width:50px;display:inline-block;">To:</label>
<input type="text" size="34" name="to" value=""/>
</p>
<p>
<label style="width:50px;display:inline-block;">Via:</label>
<select disabled name="mode" disabled>
<option value="c">Car</option>
</select>
<input type="submit" name="submit" value="Get Directions" style="margin-left:25px"/>
</p>
</form>
<?php
//PHP CODE STARTS HERE
if(isset($_GET['submit'])){
$db_name="carpool";
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$from=mysql_real_escape_string($_GET['from']);
$to=mysql_real_escape_string($_GET['to']);
$query_for_result=mysql_query("
SELECT *
FROM routedetails
WHERE `from` LIKE '%".$from."%'
AND `to` LIKE '%".$to."%'
");
echo "<table border=1 width=510>";
echo "<tr>";
echo "<td>";
echo "<h2>From: Search Results</h2><ol>";
$data_fetch=mysql_fetch_assoc($query_for_result);
while($data_fetch=mysql_fetch_assoc($query_for_result))
{
echo "<li>";
foreach($data_fetch as $row => $value){
echo "$row - $value<br />";
}
echo "</li><hr/>";
}
echo "</tr>";
echo "</td>";
echo "</table>";
echo "</ol>";
mysql_close();
}
?>
<div></td>
<td><div id="map" style="width:600px;height:600px;margin-right:20px;float:left;"></div></td>
<td><div id="panel"></div>
<script type="text/javascript" src="http://gothere.sg/jsapi?sensor=false"></script>
<script type="text/javascript">
gothere.load("maps");
//var directions;
function initialize() {
if (GBrowserIsCompatible()) {
// Create the Gothere map object.
var map = new GMap2(document.getElementById("map"));
// Set the center of the map.
map.setCenter(new GLatLng(1.362083, 103.819836), 11);
// Add zoom controls on the top left of the map.
map.addControl(new GSmallMapControl());
// Add a scale bar at the bottom left of the map.
map.addControl(new GScaleControl());
// directions.load("from: Changi Airport to: Orchard Road");
}
directions = new GDirections(map, document.getElementById("panel"));
}
function getDirections(from, to, mode) {
var travelMode;
directions.load("from: " + from + " to: " + to, {travelMode: travelMode});
}
gothere.setOnLoadCallback(initialize);
</script></td>
</tr>
</table>
</body>
</html>
You have invalid html code, you are opening your ordered list <ol> inside a cell <td><h2>...</h2><ol>, but closing it outside table </table></ol>, and you are closing your cell after your row </tr></td>. Your output code currently looks like this -
<table border=1 width=510>
<tr>
<td>
<h2>From: Search Results</h2>
<ol>
<li>$row - $value<br /></li>
<hr/>
</tr>
</td>
</table>
</ol>
Also, try removing $data_fetch=mysql_fetch_assoc($query_for_result); as it is a duplicate of the next line while($data_fetch=mysql_fetch_assoc($query_for_result))

Dynamic table along with value

JQUERY
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script type="text/javascript">
$('#aggiungi').live('click', function(){
var thisRow = $(this).parent().parent();
// clone and add data
thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
$(this).val("-");
$(this).attr("id","remove");
var nextRow = thisRow.next();
nextRow.find('input:not(#aggiungi)').val("");
if (thisRow.data('is_clone')){
while(thisRow.data('is_clone')){
thisRow = thisRow.prev();
}
}else{
nextRow.children(":first").remove();
}
currRowSpan = thisRow.children(":first").attr("rowspan");
thisRow.children(":first").attr("rowspan", currRowSpan+1);
});
$('#remove').live('click', function(){
var thisRow = $(this).parent().parent(),
prevRow = thisRow.prev();
if (thisRow.data('is_clone')){
while(prevRow.data('is_clone')){
prevRow = prevRow.prev();
}
}else{
prevRow = thisRow.next()
.removeData('is_clone')
.children(":first")
.before(thisRow.children(":first"))
.end();
}
currRowSpan = prevRow.children(":first").attr("rowspan");
prevRow.children(":first").attr("rowspan", currRowSpan-1);
thisRow.remove();
});
</script>
PHP
<form action="grading.php" method="post">
<table width-"100%" id="tableRealizzazione">
<tr>
<th></th>
<th style="padding:12px;text-align:center;">Personale</th>
<th style="padding:12px;text-align:center;">Percentage</th>
<th style="padding:12px;text-align:center;">Marketing point</th>
<th style="padding:12px;text-align:center;">Add/Remove</th>
</tr>';
echo '<tr class="even">
<td></td>
<td style="padding:12px;"><input type="text" value="" id="Personale" name="Personale"></td>
<td style="padding:12px;">
<input type="text" id="from" name="from" size="5%"> -
<input type="text" id="to" name="to" size="5%"> %
</td>
<td style="padding:12px;"><input type="text" class="totaliCostiGestione" id="marketpt" name="marketpt"></td>
<td style="padding:12px;"><input type="text" name="programid" value ="34" size="10%"></td>
<td style="padding:12px;"><input type="button" value="+" id="aggiungi"/></td>';
echo '</tr>';
echo '<tr><td><input type="submit" name="submit" value="submit"></td></tr>';
echo '</table>
</form>
When I fill the values of all text boxes and click submit, it prints only the last row and the the last row with value 34 not repeating for all the rest rows.
Here is my code in Fiddle
http://jsfiddle.net/gansai/PA9JF/
That is because you have to make arrays from your form:
eg:
<input type="text" id="from" name="from[]" size="5%"> -
to clone values you have to add:
newRow = thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
$(newRow+"[name^=programid]").val($(thisRow+"[name^=programid]").val());
Like this JSFiddle
then in PHP:
foreach($_POST['marketpt'] as $num => $val){
$Personale = $_POST[$num]['Personale'];
$from = $_POST[$num]['from'];
$to = $_POST[$num]['to'];
$marketpt = $_POST[$num]['marketpt'];
$programid = $_POST[$num]['programid'];
// process variables, eg: insert in database
}

PHP _POST array is empty

I just don't see the problem. Need some new eyes to review it. Two files included test.php and test2.php to var_dump. Help!! Cut, Paste and Run - Thanks
test.php:
<?php
ini_set('error_reporting', E_ALL );
ini_set('display_errors', "1");
?>
<style type="text/css">
div.tabcontent{
visibility: hidden;
position:absolute;
left:20px;
}
</style>
<script type="text/javascript">
function switch_div(){
val=document.form1.a_type.selectedIndex;
if (val < 3){
val="a0";
data=document.getElementById("data_types").innerHTML+document.getElementById(val).innerHTML;
}else if (val==3){
val="a"+document.form1.a_type.selectedIndex;
data=document.getElementById("data_types").innerHTML+document.getElementById(val).innerHTML;
}else{
val="a"+document.form1.a_type.selectedIndex;
data=document.getElementById(val).innerHTML;
}
document.getElementById('anw_wksp').innerHTML=data;
}
</script>
<html>
<body>
<form name="form1" action="test2.php" method="post" >
<table>
<th >Enter Anwsers</th>
<tr>
<td>Anwser Type</td>
</tr>
<tr>
<td><select name="a_type" onChange="switch_div()"/>
<option value='radio'>radio</option>
<option value='checkbox'>checkbox</option>
<option value='select'>select</option>
<option value='text'>text</option>
<option value='textarea'>textarea</option>
</select>
</td>
</tr>
<div id="anw_wksp" style="border:1px solid gray; margin-bottom: 1em; padding: 10px">
</div>
<div id="data_types" class="tabcontent">
<table>
<th colspan="3">Data type</th>
<tr><td>
<input type="radio" name="a_data_type" value="text" selected>text<br>
<input type="radio" name="a_data_type" value="int">int </td>
</td>
</tr>
</table>
</div>
<div id="a0" class="tabcontent"> <!--radio/checkbox/select button-->
<table>
<th>Readable Anwser</th><th>DB Value</th><th>Default</th>
<? $i=0;
while($i < 10){
echo "<tr><td><input type=\"text\" name=\"a_r_$i\" /></td>
<td><input type=\"text\" name=\"a_db_$i\" /></td>
<td><input type=\"radio\" name=\"default\" value=\"$i\" /></td></tr>";
$i++;
}
?>
</table>
</div>
<div id="a3" class="tabcontent">
<table>
<th>Readable Anwser</th><th>DB Value</th><th>Default</th>
<tr><td><input type="text" name="a_r_text"></td>
<td><input type="text" name="a_db_text"></td>
<td><input type="text" name="default_text" ></td></tr>
</table>
</div>
<div id="a4" class="tabcontent">
<table>
<th>Readable Anwser</th><th>Default</th>
<tr><td><input type="text" name="a_r_textarea"></td>
<td><textarea name="default_textarea" rows="5" cols="30"></textarea></td></tr>
</table>
</div>
</td>
</tr>
</td>
</tr>
<tr>
<td><input type="submit" value="Enter" name="submit">
</td>
</table>
</form>
</body>
</html>
<script language="javascript">switch_div();</script>
-------------------------------------------------------------------
test2.php:
<?php
$data = file_get_contents('php://input');
if(empty($_SERVER['CONTENT_TYPE'])){
$type = "application/x-www-form-urlencoded";
$_SERVER['CONTENT_TYPE'] = $type;
}
print "_POST = <br />";
var_dump($_POST);
print "<br />";
print " DATA = <br />";
var_dump($data);
?>
You don't have a <head>
You can't have <script> tags outside of your <html>. Perhaps you want external JS files?
You can't have <style> tags outside of your <html>. Perhaps you want external CSS files?
Your scripts/styles, or their external <link>'s, should probably be inside your <head>
You can't have <th> or <td> outside of a <tr>. Proper example.
You don't declare a doctype.
You can't have <div>'s randomly between table rows.
Your method for echoing <tr>'s is, well, sloppy...
Instead of:
<? $i=0;
while($i < 10){
echo "<tr><td><input type=\"text\" name=\"a_r_$i\" /></td>
<td><input type=\"text\" name=\"a_db_$i\" /></td>
<td><input type=\"radio\" name=\"default\" value=\"$i\" /></td></tr>";
$i++;
}
?>
Consider something like:
<? for($i = 0; $i < 10; $i++) { ?>
<tr>
<td><input type="text" name="a_r_<?=$i?>" /></td>
<td><input type="text" name="a_db_<?=$i?>" /></td>
<td><input type="radio" name="default" value="<?=$i?>" /></td>
</tr>
<? } ?>
Finally, to try debugging your problem, use a tool like Firebug for Chrome/Firefox to ensure you're submitting POST data as expected.
I know this is a lame answer but just want to throw it out there to make sure we aren't looking over the simplest things. Did you check the form tag in the html to make sure it is set to POST?
I would recommend checking that the request method is in fact a post on the test2.php script.
<?php
if (strtolower($_SERVER["REQUEST_METHOD"]) == "post") {
$data = file_get_contents('php://input');
if(empty($_SERVER['CONTENT_TYPE'])){
$type = "application/x-www-form-urlencoded";
$_SERVER['CONTENT_TYPE'] = $type;
}
print "_POST = <br />";
var_dump($_POST);
print "<br />";
print " DATA = <br />";
var_dump($data);
}
?>

Categories