HTML - Issue with form submission - html

Issue with submitting form, I don't see anything wrong with the form section.
This is an example of my code, The ticket number and user ID is being pushed into from MYSQL. When it gets to the server side after submitting, I am getting only 2 of 21 items. The readonly is only on the top 2 items, the rest is entered by end user.
<form action="<?php echo $NAV_includes_Research_Upload; ?>" method="POST">
<table class="Table_Center">
<tr>
<td>Ticket number:</td>
<td><input type="text" id="ticket" class="all" value="<?php echo "1"; ?>" readonly></td>
</tr>
<tr>
<td>User ID:</td>
<td><input type="text" id="user" class="all" value="<?php echo "test"; ?>" readonly>
</tr>
<tr>
<td>Site:</td>
<td><input type="url" id="website" class="all" autofocus required <?php if ($testing === 'ON') {echo 'value="http://www.google.com"';}?>></td>
</tr>
</table>
<table class="Table_Center">
<tr>
<td><input type="reset" value="Reset"></td>
<td><input type="submit" class="f_right" value="Submit"></td>
</tr>
</table>
</form>
Thank you, it was the name section that was missing.
I will have to remember that.

In your form code, I am unable to find name attribute of input fields. In an HTML form Post, values entered by the user and submitted are called by the name attribute.

Related

The post method is not supported for this route

I'm new to laravel and I want to submit a form which have three attachments plus some arrays
but when I click submit button laravel says
"The POST method is not supported for this route. Supported methods: GET, HEAD."
I've searched a lot but couldn't find any errors
My View
<div>
<form action="insertquotation" method="post" enctype="multipart/form-data">
#csrf
<table border="1" id="formTable">
<thead>
<tr>
<td>procurment_request_number</td>
<td>quotationer</td>
<td>shop_name</td>
<td>shop_account_number</td>
<td>shop_permit</td>
<td>shop_quatation</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="procurment_request_number" id="procurment_request_number" value="{{$result->first()->request_number}}">
{{--<select name="procurment_request_number[]" id="procurment_request_number">--}}
{{--#foreach($result as $results)--}}
{{--<option value="{{$results->request_number}}">{{$results->request_number}}</option>--}}
{{--#endforeach--}}
{{--</select>--}}
</td>
<td><input type="text" id="quotationer1" name="quotationer1"></td>
<td><input type="text" name="shop_name1" id="shop1_name"></td>
<td><input type="text" name="shop_account_number1" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit1" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation1" id="shop_quatation"></td>
</tr>
<tr>
<td></td>
<td><input type="text" id="quotationer" name="quotationer2"></td>
<td><input type="text" name="shop_name2" id="shop1_name"></td>
<td><input type="text" name="shop_account_number2" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit2" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation2" id="shop_quatation"></td>
</tr>
<tr>
<td></td>
<td><input type="text" id="quotationer" name="quotationer3"></td>
<td><input type="text" name="shop_name3" id="shop1_name"></td>
<td><input type="text" name="shop_account_number3" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit3" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation3" id="shop_quatation"></td>
</tr>
<tr>
<td>Item_ID</td>
<td>Quantity</td>
<td>Unit_ID</td>
<td>description</td>
<td>Shop1_price</td>
<td>Shop2_price</td>
<td>Shop3_price</td>
</tr>
#foreach($result as $results)
<tr>
<td><input type="text" name="itemid[]" id="itemid" value="{{$results->id}}"></td>
<td><input type="text" name="quantity[]" id="quantity" value="{{$results->quantity}}"></td>
<td><input type="text" name="units_id[]" id="units_id" value="{{$results->units_id}}"></td>
<td><input type="text" name="description[]" id="description" value="{{$results->description}}"></td>
<td><input type="text" name="shop1_price[]" id="shop1_price"></td>
<td><input type="text" name="shop2_price[]" id="shop2_price"></td>
<td><input type="text" name="shop3_price[]" id="shop3_price"></td>
</tr>
</tbody>
#endforeach
</table>
{{--<input value="addrow" type="button" id="addrow" onclick="javascript: addRow();">--}}
<input type="submit" value="submit">
</form>
</div>
My Controller
public function insertquotation(request $request)
{
if ($file = $request->file('shop1_quatation')) {
$name = $file->getClientOriginalName();
$file->move('procurement_files', $name);
$file2 = $request->file('shop2_quatation');
$name2 = $file2->getClientOriginalName();
$file2->move('procurement_files', $name2);
$file3 = $request->file('shop2_quatation');
$name3 = $file2->getClientOriginalName();
$file3->move('procurement_files', $name3);
$procurment_request_number = $request->input('procurment_request_number');
$quotationer1 = $request->input('quotationer1');
$quotationer2 = $request->input('quotationer2');
$quotationer3 = $request->input('quotationer3');
$shop_name1 = $request->input('shop_name1');
$shop_account_number1 = $request->input('shop_account_number1');
$shop_permit1 = $request->input('shop_permit1');
$shop_name2 = $request->input('shop_name2');
$shop_account_number2 = $request->input('shop_account_number2');
$shop_permit2 = $request->input('shop_permit2');
$shop_name3 = $request->input('shop_name3');
$shop_account_number3 = $request->input('shop_account_number3');
$shop_permit3 = $request->input('shop_permit3');
$numbers = $request->input('itemid');
for ($i = 0; $i < count($numbers); $i++) {
$itemid = $request->input('itemid');
$shop1_price = $request->input('shop1_price');
$shop2_price = $request->input('shop2_price');
$shop3_price = $request->input('shop3_price');
DB::insert("INSERT INTO procurment_quotations (`procurment_request_number`, `itemid`, `quotationer1`, `quotationer2`, `quotationer3`, `shop1_name`, `shop1_account_number`, `shop1_permit`, `shop1_quatation`, `shop1_price`, `shop2_name`, `shop2_account_number`, `shop2_permit`, `shop2_quatation`, `shop2_price`, `shop3_name`, `shop3_account_number`, `shop3_permit`, `shop3_quatation`, `shop3_price`, `created_at`, `updated_at`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)", [$procurment_request_number, $itemid[$i],$quotationer1,$quotationer2,$quotationer3,$shop_name1,$shop_account_number1,$shop_permit1,$name,$shop1_price,$shop_name2,$shop_account_number2,$shop_permit2,$name2,$shop2_price,$shop_name3,$shop_account_number3,$shop_permit3,$name3,$shop3_price]);
}
}
}
and my route
Route::Post('insertquotation','Home#insertquotation');
The error is
"The POST method is not supported for this route. Supported methods: GET, HEAD."
Give the route a name in your routes/web.php file:
Route::post('insertquotation','Controllername#methodname')
->name('insertquotation');
And then change the form action in your blade file to point to that route:
<form action="{{ route('insertquotation') }}" method="post" enctype="multipart/form-data">
Couple of things which I need to point out on your code
It is always better to use route names while creating routes so that when you need to change the route URL to something else, you only need to change it inside routes file (not view files)
Route::post('insertquotation','Home#insertquotation')->name('insertquotation');
Now inside your view, you need to do this
<form method="POST" enctype="multipart/form-data" action="{{ route('insertquotation') }}"> ... </form>
In the future when you want (maybe not) to change the URL to /quotation/insert, all you have to do is to change it inside the routes file.
Now, inside your controller,
There is a function to check whether the file exists $request->hasFile('shop1_quatation') which more correct to use inside an if condition rather passes in the file.
Also, it is much better to use Laravel eloquent for inserting data into the database. Learn more here
I think from action="insertquotation", you should make it into action="{{url('insertquotation')}}"
And may I see the codes in your routes/web.php file? you should declare the route insertquotation there
For example:
Route::post('insertquotation', 'YourController#yourMethod');

Proper way to post a new form in each row of a table?

I have a page where there is a table. In each row of the table, there is data about an online grocery delivery order. At the end of each row, there is a submit button about action to be performed on the order and the form ends there. A new form begins with the next row <tr>
Where exactly should I put the <form> and </form> tags? Should I put the <form> before each <tr> and </form> after the </tr> or should I introduce them in the first data cell <td> of each row and close in the last <td>?
I mean, the page would probably function all right in both ways, but what is "proper" way of doing this? Right now mozilla code view is showing the table tag in red color.
This is how it looks right now.
And this is the relevant part of the php code I am using to dynamically generate a new form for each table row. I am posting this just for the sake of reference, because this does not matter at all here. My question is basic HTML based, not php based.
for($i=0;$i<$count;++$i){
$res.='<form action="" method="post">' ."\n" .'<input type="hidden" name="orderid" value="' .$orders[$i]->idcode .'" />';
$res.="$nt<tr><td align=\"center\">" .$orders[$i]->display("pe","</td><td align=\"center\">") ."</td>$nt\t<td align=\"center\"><select name=\"agent\">$alistcode</select></td>$nt\t<td align=\"center\"><select name=\"vendor\">$vlistcode</select></td>";
$res.="$nt\t<td align=\"center\"><input type=\"submit\" value=\"PROCESS\" /></td>\n</tr>\n</form>\n";
}
$res.="</table>";
echo $res;
HTML5 offers decent solution for your problem. And its name is form attribute. Just put the form into last <td> and refer to its id from other inputs. See example.
<table>
<tr>
<td>
<input type="text" name="inp1" form="form1" />
</td> <!-- ^^^^ ^^^^^ -->
<td>
<form id="form1" method="get" action="/">
<!-- ^^ ^^^^^ -->
<input type="submit" name="submit1" value="submit" />
</form>
</td>
</tr>
<tr>
<td>
<input type="text" name="inp2" form="form2" />
</td>
<td>
<form id="form2" method="get" action="/"><input type="submit" name="submit2" value="submit" /></form>
</td>
</tr>
</table>
If using javascript is an option, you can work without <form> tags?
I used jQuery in this example, data is posted to itself (first argument of $.post()).
Table
<table>
<tbody>
<tr>
<td><input name="inputfield[]" type="text" value="input1" /></td>
<td><select name="selectfield[]">
<option selected value="select1-option1">select1-option1</option>
<option value="select1-option2">select1-option2</option>
<option value="select1-option3">select1-option3</option>
</select></td>
<td><a class="submit">Update</a></td>
</tr>
<tr>
<td><input name="inputfield[]" type="text" value="input2" /></td>
<td><select name="selectfield[]">
<option selected value="select2-option1">select2-option1</option>
<option value="select2-option2">select2-option2</option>
<option value="select2-option3">select2-option3</option>
</select></td>
<td><a class="submit">Update</a></td>
</tr>
<tr>
<td><input name="inputfield[]" type="text" value="input3" /></td>
<td><select name="selectfield[]">
<option selected value="select3-option1">select3-option1</option>
<option value="select3-option2">select3-option2</option>
<option value="select3-option3">select3-option3</option>
</select></td>
<td><a class="submit">Update</a></td>
</tr>
</tbody>
</table>
Script
$(".submit").on("click", function(){
var row = $(this).parents("tr");
$.post("", row.find("input, select, radio").serialize(), function(data){ console.log(data); });
});
JSFiddle

form doesnt fires submit when i press enter

I have a little question... I dont know whats happening but submit event is working because when I click "ingresar" submit button, it sends all the data.
But when I press enter nothing happens.
I think the problem is that i have the form inside of a table....
Am I wrong? I think the problem is here because,as I said, when i press Ingresar submit button it sends the data.
Thx for your help! :)
<form id="forma-recurso" method="POST">
<table >
<tr>
<td><p>Nombre recurso:</p></td>
<td><input type="text" class="campo nombre-recurso" maxlength="50"></td>
</tr>
<tr>
<td><p>Dirección:</p></td>
<td><input type="text" class="campo direccion-recurso" maxlength="50"></td>
</tr>
<tr>
<td><p>Descripción:</p></td>
<td><input type="text" class="campo descripcion-recurso" maxlength="100"></td>
</tr>
<tr>
<td><p>Tipo de punto de interés:</p></td>
<td><select type="text" class="campo tipo-pto-interes">
<?php
$conexion=pg_connect("host= localhost port=5432 dbname=EmergenciesResponse user=postgres password=asdf");
$registros=pg_query("select tipo_pto, tipo_pto_interes from tipos_ptos_interes where tipo_pto_interes BETWEEN 1 AND 4");
while ($reg=pg_fetch_array($registros))
{
echo "<option value=\"$reg[tipo_pto_interes]\">$reg[tipo_pto]</option><br>";
}
pg_close($conexion);
?>
</select></td>
</tr>
<tr>
<td><p>Latitud/longitud</p></td>
<td><input type="text" class="latlng" disabled></td>
</tr>
<tr>
<td class="salida-btn"><button class="btn-salir">Salir</button></td>
<td class="ingreso-boton"> <input type="submit" class="ingresar-recurso"value="Ingresar"></td>
</tr>
</table>
</form>
Your HTML code seems to be okay, so there must be something in your browser or in the PHP code: the "enter submit" doesn't work when the submit button is not present in the form, otherwise, it should work.
You can see if it is working using inspector tool, press f12 to open it in your browser, change to networking tab, and try to click on submit button if something happens its ok.
I notice that in your form you are not using action form atribute, try it like this example: http://www.w3schools.com/html/html_forms.asp

Why can't I submit my form with WWW::Mechanize::Firefox in Perl?

I have an HTML this is part of the form I'm working on
<form action="/goform/FormUpdateVAP" autocomplete="off" name="myform" id="formid" method="POST">
<table>
<tbody>
<tr>
<td align="right"><span class="label">Name:</span></td>
<td><input id="essid" name="essid" value="X" type="text"></td>
</tr>
<tr>
<td align="right"><input id="broadcast_essid" name="broadcast_essid" value="any" checked="" type="checkbox"></td>
<td><span class="label">Broadcast name:</span></td>
</tr>
</tbody>
</table>
<!-- BEGIN RIGHT COLUMN -->
<table>
<tbody><tr>
<td>
<input name="authentication" id="authentication" value="any" onclick="Update();" type="checkbox"><span class="label"><b>authentication</b></span>
</td>
<td>
<input onclick="Update();" name="wp" id="wp" value="any" type="checkbox"><span class="label"><b>Wp</b></span>
<select id="8021x_mode" name="8021x_mode" onchange="Update();"><option value="wpa">WPA</option>
<option value="wep">WEP</option>
</select>
</td>
</tr>
<tr>
<td height="26">
<input onclick="Update();" name="w_p" id="w_p" value="any" type="checkbox"><span class="label"><b>Wp</b></span>
<select id="8021x_mode" name="8021x_mode" onchange="Update();"><option value="wpa">WPA</option>
<option value="wep">WEP</option>
</select>
</td>
</tr>
<tr>
<td>
<input id="cancel" name="cancel" value="Cancel" onclick="window.location.href = '/fg/list.asp';" type="button">
</td>
<td>
<input id="add-2" name="add" value="Save" type="submit">
</td>
</tr>
</tbody>
</table>
I'm trying to submit it filling the Name and the Broadcast name. And checking the 8021x_mode and the wp checkboxes. If I tick 8021x_mode and set the fields the form submits just fine. But when I try ticking wp it doesn't submit. I got no error messages.
Here's my code so far:
use WWW::Mechanize::Firefox;
use Crypt::SSLeay;
use URI::Fetch;
use HTML::TagParser;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; #not verifying certificate
my $url = 'https://';
$url = $url.#ARGV[0];
my $mech = WWW::Mechanize::Firefox->new;
$mech->get($url);
$mech->form_id('formid');
$mech->tick( '8021x_mode','any');
$mech->tick( 'wp','any'); --after I add this the form doesn't submit
my $name = #ARGV[1];
$mech->set_fields(
'vap_name' => $name,
'essid' => $name,
);
$mech->click_button( id => 'add-2' );
$mech->reload();
add-2 is the submit button. Any idea why is not working? If you need more information please let me now. Any help will be highly appreciated.
The problem is that the html doesn't contains the choice any for 8021x_mode.
I get this error :
No elements found for Checkbox with name '8021x_mode' and value 'any'
at test.pl line 24.
To check the form, I recommend you the mech-dump utility (installed with WWW::Mechanize)
$ mech-dump --forms http://domain.tld/path_to_forms
POST /goform/FormUpdateVAP [myform]
essid=X (text)
broadcast_essid=<UNDEF> (checkbox) [*<UNDEF>/off|any]
authentication=<UNDEF> (checkbox) [*<UNDEF>/off|any/authentication]
wp=<UNDEF> (checkbox) [*<UNDEF>/off|any/Wp]
8021x_mode=wpa (option) [*wpa/WPA|wep/WEP]
w_p=<UNDEF> (checkbox) [*<UNDEF>/off|any/Wp]
8021x_mode=wpa (option) [*wpa/WPA|wep/WEP]
cancel=Cancel (button)
add=Save (submit)
As you can see, there's no any choice...
Maybe the javascript there is doing some things that we don't know.
A workaround is to use LiveHttpHeaders Firefox addon to catch the forms POSTed to /goform/FormUpdateVAP and then instead of ticking, do a POST request with WWW::Mechanize.

HTML: Is it possible to have a FORM tag in each TABLE ROW in a XHTML valid way?

I can best describe this as follows:
I want this (entire table in editmode and save button in every row).
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Description</td>
<td> </td>
</tr>
<tr>
<td><input type="hidden" name="id" value="1" /></td>
<td><input type="text" name="name" value="Name" /></td>
<td><input type="text" name="description" value="Description" /></td>
<td><input type="submit" value="Save" /></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="2" /></td>
<td><input type="text" name="name" value="Name2" /></td>
<td><input type="text" name="description" value="Description2" /></td>
<td><input type="submit" value="Save" /></td>
</tr>
<!-- and more rows here ... -->
</table>
Where should I put the <form> tags?
It's worth mentioning that this is possible in HTML5, using the "form" attribute for input elements:
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Description</td>
<td> </td>
</tr>
<tr>
<td><form id="form1"><input type="hidden" name="id" value="1" /></form></td>
<td><input form="form1" type="text" name="name" value="Name" /></td>
<td><input form="form1" type="text" name="description" value="Description" /></td>
<td><input form="form1" type="submit" value="Save" /></td>
</tr>
<tr>
<td><form id="form2"><input type="hidden" name="id" value="1" /></form></td>
<td><input form="form2" type="text" name="name" value="Name" /></td>
<td><input form="form2" type="text" name="description" value="Description" /></td>
<td><input form="form2" type="submit" value="Save" /></td>
</tr>
</table>
While clean in its lack of JS and use of original elements, unfortunately this isn't working in IE10.
I had a similar question and this answer in question HTML: table of forms? solved it for me. (Not sure if it is XHTML, but it works in an HTML5 browser.)
You can use css to give table layout to other elements.
.table { display: table; }
.table>* { display: table-row; }
.table>*>* { display: table-cell; }
Then you use the following valid html.
<div class="table">
<form>
<div>snake<input type="hidden" name="cartitem" value="55"></div>
<div><input name="count" value="4" /></div>
</form>
</div>
You can't. Your only option is to divide this into multiple tables and put the form tag outside of it. You could end up nesting your tables, but this is not recommended:
<table>
<tr><td><form>
<table><tr><td>id</td><td>name</td>...</tr></table>
</form></td></tr>
</table>
I would remove the tables entirely and replace it with styled html elements like divs and spans.
I wrote the below over ten years ago, when the world was a different place. These days I know of many ways to crack this particular nut, but a quick and dirty solution that will validate is to do much the same but use CSS tables for layout, not a regular HTML table.
I'd say you can, although it doesn't validate and Firefox will re-arrange the code (so what you see in 'View generated source' when using Web Developer may well surprise). I'm no expert, but putting
<form action="someexecpage.php" method="post">
just ahead of the
<tr>
and then using
</tr></form>
at the end of the row certainly gives the functionality (tested in Firefox, Chrome and IE7-9). Working for me, even if the number of validation errors it produced was a new personal best/worst! No problems seen as a consequence, and I have a fairly heavily styled table. I guess you may have a dynamically produced table, as I do, which is why parsing the table rows is a bit non-obvious for us mortals. So basically, open the form at the beginning of the row and close it just after the end of the row.
The answer of #wmantly is basicly 'the same' as I would go for at this moment.
Don't use <form> tags at all and prevent 'inappropiate' tag nesting.
Use javascript (in this case jQuery) to do the posting of the data, mostly you will do it with javascript, because only one row had to be updated and feedback must be given without refreshing the whole page (if refreshing the whole page, it's no use to go through all these trobules to only post a single row).
I attach a click handler to a 'update' anchor at each row, that will trigger the collection and 'submit' of the fields on the same row. With an optional data-action attribute on the anchor tag the target url of the POST can be specified.
Example html
<table>
<tbody>
<tr>
<td><input type="hidden" name="id" value="row1"/><input name="textfield" type="text" value="input1" /></td>
<td><select name="selectfield">
<option selected value="select1-option1">select1-option1</option>
<option value="select1-option2">select1-option2</option>
<option value="select1-option3">select1-option3</option>
</select></td>
<td><a class="submit" href="#" data-action="/exampleurl">Update</a></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="row2"/><input name="textfield" type="text" value="input2" /></td>
<td><select name="selectfield">
<option selected value="select2-option1">select2-option1</option>
<option value="select2-option2">select2-option2</option>
<option value="select2-option3">select2-option3</option>
</select></td>
<td><a class="submit" href="#" data-action="/different-url">Update</a></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="row3"/><input name="textfield" type="text" value="input3" /></td>
<td><select name="selectfield">
<option selected value="select3-option1">select3-option1</option>
<option value="select3-option2">select3-option2</option>
<option value="select3-option3">select3-option3</option>
</select></td>
<td><a class="submit" href="#">Update</a></td>
</tr>
</tbody>
</table>
Example script
$(document).ready(function(){
$(".submit").on("click", function(event){
event.preventDefault();
var url = ($(this).data("action") === "undefined" ? "/" : $(this).data("action"));
var row = $(this).parents("tr").first();
var data = row.find("input, select, radio").serialize();
$.post(url, data, function(result){ console.log(result); });
});
});
A JSFIddle
You just have to put the <form ... > tag before the <table> tag and the </form> at the end.
Hopte it helps.
In fact I have the problem with a form on each row of a table, with javascript (actually jquery) :
like Lothre1 said, "some browsers in the process of rendering will close form tag right after the declaration leaving inputs outside of the element"
which makes my input fields OUTSIDE the form, therefore I can't access the children of my form through the DOM with JAVASCRIPT..
typically, the following JQUERY code won't work :
$('#id_form :input').each(function(){/*action*/});
// this is supposed to select all inputS
// within the form that has an id ='id_form'
BUT the above exemple doesn't work with the rendered HTML :
<table>
<form id="id_form"></form>
<tr id="tr_id">
<td><input type="text"/></td>
<td><input type="submit"/></td>
</tr>
</table>
I'm still looking for a clean solution (though using the TR 'id' parameter to walk the DOM would fix this specific problem)
dirty solution would be (for jquery):
$('#tr_id :input').each(function(){/*action*/});
// this will select all the inputS
// fields within the TR with the id='tr_id'
the above exemple will work, but it's not really "clean", because it refers to the TR instead of the FORM, AND it requires AJAX ...
EDIT : complete process with jquery/ajax would be :
//init data string
// the dummy init value (1=1)is just here
// to avoid dealing with trailing &
// and should not be implemented
// (though it works)
var data_str = '1=1';
// for each input in the TR
$('#tr_id :input').each(function(){
//retrieve field name and value from the DOM
var field = $(this).attr('name');
var value = $(this).val();
//iterate the string to pass the datas
// so in the end it will render s/g like
// "1=1&field1_name=value1&field2_name=value2"...
data_str += '&' + field + '=' + value;
});
//Sendind fields datawith ajax
// to be treated
$.ajax({
type:"POST",
url: "target_for_the_form_treatment",
data:data_string,
success:function(msg){
/*actions on success of the request*/
});
});
this way, the "target_for_the_form_treatment" should receive POST data as if a form was sent to him (appart from the post[1] = 1, but to implement this solution i would recommand dealing with the trailing '&' of the data_str instead).
still I don't like this solution, but I'm forced to use TABLE structure because of the dataTables jquery plugin...
Im late to the party, but this worked great for me and the code should explain itself;
<script type="text/javascript">
function formAJAX(btn){
var $form = $(btn).closest('[action]');
var str = $form.find('[name]').serialize();
$.post($form.attr('action'), str, function(data){
//do stuff
});
}
<script>
HTML:
<tr action="scriptURL.php">
<td>
Field 1:<input type="text" name="field1"/>
</td>
<td>
Field 2:<input type="text" name="field2" />
</td>
<td><button type="button" onclick="formAJAX(this)">Update</button></td>
</tr>
If you try to add a form warping a tr element like this
<table>
<form>
<tr>
<td><input type="text"/></td>
<td><input type="submit"/></td>
</tr>
</form>
</table>
some browsers in the process of rendering will close form tag right after the declaration leaving inputs outside of the element
something like this
<table>
<form></form>
<tr>
<td><input type="text"/></td>
<td><input type="submit"/></td>
</tr>
</table>
This issue is still valid for warping multiple table cells
As stereoscott said above, nesting tables are a possible solution which is not recommended.
Avoid using tables.
<table >
<thead >
<tr>
<th>No</th><th>ID</th><th>Name</th><th>Ip</th><th>Save</th>
</tr>
</thead>
<tbody id="table_data">
<tr>
<td>
<form method="POST" autocomplete="off" id="myForm_207" action="save.php">
<input type="hidden" name="pvm" value="207">
<input type="hidden" name="customer_records_id" value="2">
<input type="hidden" name="name_207" id="name_207" value="BURÇİN MERYEM ONUK">
<input type="hidden" name="ip_207" id="ip_207" value="89.19.24.118">
</form>
1
</td>
<td>
207
</td>
<td>
<input type="text" id="nameg_207" value="BURÇİN MERYEM ONUK">
</td>
<td>
<input type="text" id="ipg_207" value="89.19.24.118">
</td>
<td>
<button type="button" name="Kaydet_207" class="searchButton" onclick="postData('myForm_207','207')">SAVE</button>
</td>
</tr>
<tr>
<td>
<form method="POST" autocomplete="off" id="myForm_209" action="save.php">
<input type="hidden" name="pvm" value="209">
<input type="hidden" name="customer_records_id" value="2">
<input type="hidden" name="name_209" id="name_209" value="BALA BAŞAK KAN">
<input type="hidden" name="ip_209" id="ip_209" value="217.17.159.22">
</form>
2
</td>
<td>
209
</td>
<td>
<input type="text" id="nameg_209" value="BALA BAŞAK KAN">
</td>
<td>
<input type="text" id="ipg_209" value="217.17.159.22">
</td>
<td>
<button type="button" name="Kaydet_209" class="searchButton" onclick="postData('myForm_209','209')">SAVE</button>
</td>
</tr>
</tbody>
</table>
<script>
function postData(formId,keyy){
//alert(document.getElementById(formId).length);
//alert(document.getElementById('name_'+keyy).value);
document.getElementById('name_'+keyy).value=document.getElementById('nameg_'+keyy).value;
document.getElementById('ip_'+keyy).value=document.getElementById('ipg_'+keyy).value;
//alert(document.getElementById('name_'+keyy).value);
document.getElementById(formId).submit();
}
</script>