helloise Posted June 1, 2011 Share Posted June 1, 2011 i have this code in a foreach that lists uniquecode links: <a id="<?php echo $id_to ?>" href="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" > <?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?> </a> <form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>"> <textarea name="message" rows="10" cols="20"></textarea> <input name="Submit" type="submit" value="Send"></input> </form> this is what i get when i view the page source : <a href="http://www-rainbowcode-mobi/messageSent.php?id=36" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" > KUZELJA<span class="pink_text">000</span>RC </a> <form id="message_area" style="display:none" method="post" action="http://www-rainbowcode-mobi/messageSent.php?id=36"> <textarea name="message" rows="10" cols="20"></textarea> <input name="Submit" type="submit" value="Send"></input> </form> <a href="http://www-rainbowcode-mobi/messageSent.php?id=38" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" > ALANZIM<span class="pink_text">000</span>RC </a> <form id="message_area" style="display:none" method="post" action="http://www-rainbowcode-mobi/messageSent.php?id=38"> <textarea name="message" rows="10" cols="20"></textarea> <input name="Submit" type="submit" value="Send"></input> </form> the problem is when the action fires and page goes to messageSent and i view page source again $id_to is NOT the id of the link i clicked on..it takes the first link's id regardless of which link i click on??? here the messageSent page source( i clicked on link with id 38 NOT 36): where i have a print_r($_REQUEST) and it gives: Array ( [id] => 36 [message] => bj,nbgj, [submit] => Send ) please urgent help needed... thank you Quote Link to comment https://forums.phpfreaks.com/topic/238072-desperate-help-needed-with-form-action/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 1, 2011 Share Posted June 1, 2011 A) If you have an initial <form> tag (with out a closing </form> tag), before the start of your foreach(){} loop that outputs the code you did post, it will WIN and be the ?id= value that gets used when you submit any of the forms that would then be inside that initial form tag. B) Your showMessageArea() javascript function or some other javascript you have on the page could have something to do with this, especially since you have assigned the same id="message_area" to every form (id's must be unique.) C) Your messageSent.php code could be doing something to cause the value to be altered. Quote Link to comment https://forums.phpfreaks.com/topic/238072-desperate-help-needed-with-form-action/#findComment-1223465 Share on other sites More sharing options...
helloise Posted June 1, 2011 Author Share Posted June 1, 2011 thank you B) is the exact issue so i have altered my code like this: function showMessageArea(link, id) { document.getElementById('message_id').value = id; var message_area = document.getElementById('message_area'); //if i concatenate id here to message_area it also does not get message area to show message_area = message_area+id; message_area.parentNode.removeChild(message_area); link.parentNode.insertBefore(message_area, link.nextSibling); message_area.style.display="block"; } where id is now the correct value of the link i clicked on and the link that gets paseds is also correct : <a href="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to; ?>" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this, '<?php echo $id_to; ?>'); return false;" > <?php echo $uniqueCode1;?><span class="pink_text"><?php echo $uniqueCode2;?></span><?php echo $uniqueCode3;?> </a> <form id="message_area" style="display:none" method="post" > <textarea name="message" rows="10" cols="20"></textarea> <input name="Submit" type="submit" value="Send"></input> <input type='hidden' name='id' id='message_id' value=""></input> </form> the last little thing now is to get the message area an submit to show because it is STILL not showing Quote Link to comment https://forums.phpfreaks.com/topic/238072-desperate-help-needed-with-form-action/#findComment-1223479 Share on other sites More sharing options...
PFMaBiSmAd Posted June 1, 2011 Share Posted June 1, 2011 You would need to make the id in the <form tag match - id="message_area<?php echo $id_to; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/238072-desperate-help-needed-with-form-action/#findComment-1223485 Share on other sites More sharing options...
helloise Posted June 1, 2011 Author Share Posted June 1, 2011 thank you so much, i finally got it to work Quote Link to comment https://forums.phpfreaks.com/topic/238072-desperate-help-needed-with-form-action/#findComment-1223498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.