views:

126

answers:

3

No value is sent to $_POST['addEdit'] variable :(, pls help

HTML code:

<form name='frm' method='POST' action=''>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr class="heading">
<td style="width:5px;"><input type="checkbox" name='check_all' onClick='checkAll();' /></td>
<td class="head">App Name</td>
.
.
<?php
//some embeded php (here is the addEdit component)
.
.
echo '
<td id="row_'.$row['id'].'" style="display: none;">
 <input type="text" name="addEdit" id="addEdit_row_'.$row['id'].'" value="" size="4"/></td>
<td>
        <input type="submit" name="add" value="A"  onClick="addObs('.$row['id'].'); return false;"/>
';
</td>
.
.//end oh php code
?>
<!-- end of html code -->

PHP code:

if(isset($_POST['add']))
{
 //echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
 if (isset($_POST['addEdit']))
 {
  echo 'post: '.$_POST['addEdit'];
 }
}
+2  A: 

Did you close <form> tag ?

Try to:

var_dump($_POST);
hsz
Yes, the form is closed
Claudiu
Ok but what do you have in `var_dump` ?
hsz
string(0) "" this is the output :(
Claudiu
As a whole `$_POST` ? `$_POST` should be in the worst case an empty array but not string ! So you must overwriting this `$_POST` with some other value.
hsz
However `<input type="text" name="addEdit" ...` has no value param.
hsz
sry, Ive dumped my varthis is what you've asked:array(2) { ["addEdit"]=> string(0) "" ["add"]=> string(1) "A" }
Claudiu
I`ve added value="", still no value in POST :(
Claudiu
`value=""` gives you empty string -> `string(0) ""` :) Try to set some value -> `value="test"` and in `$_POST` you will get this `test` value.
hsz
Yes, thats true, but I don`t think I need any value parameter because I take the value from the input field; what should I do ? :(
Claudiu
I said you to set `value` in your `HTML`. I do not know what have you done now, but in your `HTML` code you give us there is empty `value` parameter in `addEdit` input. If you set something there, you will have it in `$_POST` in `PHP.
hsz
If I write the parameter value="test" then "test" would come through POST, but I want the value parameter to be populated with the string from the input box;
Claudiu
In you write down something in this `input` it will be `POST`'ed to `PHP`.
hsz
I wish, that`s why I wrote this topic
Claudiu
+1  A: 

Try

<form name='frm' method='POST' action='<?php echo $_SERVER['PHP_SELF']?>'>   
iainco
Empty `action` param gives current addres also.
hsz
Ok, my bad. The addEdit input element has no value, but when the form is submitted it should be present in the $_POST global. Can you paste the HTML of the page when fully loaded so we can see what is echoed?
iainco
<td id="row_30126" style="display: none;"><input type="text" name="addEdit" id="addEdit_row_30126" size="4"/></td><td><input type="submit" name="add" value="A" onClick="addObs(30126); return false;"/></td>
Claudiu
from what I can see your PHP output is probably going to be "post: "... there is no value for the addEdit element. If it was <input type="text" name="addEdit" id="addEdit_row_30126" value="addEdit_row_30126" size="4"/> then your PHP output would be "post: addEdit_row_30126"
iainco
could you write exactly the value parameter ?
Claudiu
You would type something into that textbox which will be stored in the POST global, so if you type "hello" into the addEdit text field, the POST global would have an element named "addEdit" and it's value would be "hello". If you set the value dynamically using PHP, then it will appear in the text box and it will be that value that is submitted unless you type something different.
iainco
I don't know how to set the value dynamically :(
Claudiu
in your php code, you've got value="", you can set the value there using a variable, that would be setting it dynamically.
iainco
so, you saing that I should read the value from addEdit component, write it to a variable $temp, then set value=$temp on the same addEdit component, it makes no sense to me, sry
Claudiu
If you want to be able to type something into the addEdit text box, then forget about setting the input value (<input type="text" value="???"). If you don't type anything in the addEdit text box, and submit the form, $_POST['addEdit'] will be set to "" (empty string)... else it will equal what you typed into the text box. I'm not sure what else you are trying to do.
iainco
my problem is: the the string typed in the addEdit text box doesn't get sent to the $_POST variable; what should I modify so I can receive something through $_POST['addEdit'] ?
Claudiu
A: 

ANY OTHER HELP ?

Claudiu
SOLVED, the problem was that the Add submit button (that I was using to read data from AddEdit input box) is not the main submit button of my form frm. I`ve just created a nested form containing the input box AddEdit and the button Add.Than you all for willing to help
Claudiu