Forum Moderators: coopster

Message Too Old, No Replies

Can't get update procedure working (with textarea)

         

pixeldiver

12:52 am on Mar 2, 2010 (gmt 0)

10+ Year Member



Hello everyone,

I have the following problem:
I am populating a table row with a textarea where people can write comments to product orders.

$output[] = '<td align="center" width="100"><textarea name="specifics'.$id.'" value="'.specifics.'" cols="35" rows="5"></textarea></td>';

Here is the function "update" where the cart should be updated with the new comments and it should populate the rows with new comments in the textareas.

At the moment it populates the rows perfect BUT if I try to add a comment to the textarea and submit the form it doesen't return the rows anymore.

// Function update
case 'update':
if ($cart2) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'specifics')) {
$id = str_replace('specifics','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart2);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart2 = $newcart;
break;

Any help would be appreciated !

Matthew1980

8:17 am on Mar 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there pixeldiver,


$output[] = '<td align="center" width="100"><textarea name="specifics'.$id.'" value="'.specifics.'" cols="35" rows="5"></textarea></td>';


Are you missing a $ off the concatonated word in the value attribute? Looks like it should be a var to me..

$output[] = '<td align="center" width="100"><textarea name="specifics'.$id.'" value="'.$specifics.'" cols="35" rows="5"></textarea></td>';


And if your trying to echo the contents of the var, it should be placed between the textarea tags: <textarea>'.$yourvar.'</textarea>

Cheers,

MRb

pixeldiver

9:55 pm on Mar 2, 2010 (gmt 0)

10+ Year Member



Thanks Matthew1980,

I have changed the missing $ and put in the var to output the input text.
It still doesn't work: after submitting the form the row with the textarea dissapears.

Cheers

M

Matthew1980

10:46 pm on Mar 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Pixeldiver,

Oops, my mistake I think, I have just read your code again, and this time i have re-typed it out a bit better ;-p :-


$output[] = "<td align=\"center\" width=\"100\"><textarea name=\"specifics".$id."\" cols=\"35\" rows=\"5\">".(isset($specifics) ? $specifics : "")."</textarea></td>";


Just copy and paste that as the code view doesn't make the single/double quotes easy to tell apart...

I don't think as the value attribute is needed (I could be wrong) as it is meant to be echoed into the gap between the tags.

I have re-done the $output[] with the double quotes (not necessary but I think as this is just the one line, what the hell..) but the drawback is you need to escape the \" quotes, toothpicks all over the place. Tsk Tsk!

I have written this so that if the var specifics is only echoed if it is set, else it outputs nothing.

That should make that part of your code work nicely, but as for the other, I'm not quite sure, hopefully someone else will spot something (if anything) wrong.

Hope this helps..

Cheers,

MRb

pixeldiver

11:00 pm on Mar 2, 2010 (gmt 0)

10+ Year Member



Thanks Mate,

I have put this in as is: still doing the same, no output after submit. I think there is something wrong with the case 'update'.

Cheers

M