Kane250 Posted March 30, 2009 Share Posted March 30, 2009 Hello PHP Gurus... Is there any way to pass text into PHP from a div? I have been trying to set up divs inside a form which posts to the page, but since a div is not an input type, maybe this isn't possible? I have the div name and id's set correctly and PHP is looking for their POST, but I just keep getting blank entries. Am I being a moron, or is this not something PHP can do? Thanks! Quote Link to comment Share on other sites More sharing options...
sdi126 Posted March 30, 2009 Share Posted March 30, 2009 You are correct that a div is not a valid form element...which is why PHP can't pick up the posted value from a div. You can still display the text in a div...but you might also want to put it to a hidden form element. <input type="hidden" name="someName" value="theSameStuffThatIsInTheDiv" /> Quote Link to comment Share on other sites More sharing options...
Kane250 Posted March 30, 2009 Author Share Posted March 30, 2009 Thanks, that makes more sense. One last thing then. The value that is being passed into the div is from a POST variable coming from the page before it. People are actually going to be able to edit the text in this div (with ajax) eventually, so how can I set that up so the hidden field is not setting its value to the original POST value? ex: Here is what the div is getting now from the previous page. <div class="finalPara" name="finalFirstPara"> <?php print($_POST['firstParaText']); ?> </div> Since the text will likely change on this page, using this code: <input type="hidden" name=<?php $_POST['firstParaText'] ?> > will not allow me to pass the updated text. Get me? Any Idea? Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 why not use a textarea instead of a div, then pass the textarea through your form ? Quote Link to comment Share on other sites More sharing options...
Kane250 Posted March 30, 2009 Author Share Posted March 30, 2009 strictly for design purposes, it cannot look like a text field. It has to look like static text (even though ajax will be allowing it to be edited in place). Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 31, 2009 Share Posted March 31, 2009 what if you use a textarea and then use CSS to style it to look like the rest of your page ? just another idea Quote Link to comment Share on other sites More sharing options...
Kane250 Posted March 31, 2009 Author Share Posted March 31, 2009 hmm, might be an idea, except that textareas look different in different browsers, and even just the corner piece of a textarea that allows for resizing in some browsers, will mess up the design. Basically, it is supposed to look like an image... good thinking though, I can see what CSS tricks there are if nothing else! Quote Link to comment Share on other sites More sharing options...
Andy-H Posted March 31, 2009 Share Posted March 31, 2009 <style type="text/css"> <!-- textarea.finalPara { margin: 0; padding: 10px; height: 480px; width: 330px; border: 1px solid #000000; overflow: hidden; } --> </style> <textarea class="finalPara" name="finalFirstPara" id="finalFirstPara"> <?php echo stripslashes(htmlentities($_POST['firstParaText'], ENT_QUOTES)); ?> </textarea> Try something along those lines, just make sure that if you use a margin set the padding to 0 and vice versa as ie and opera vary on default spacing. Also, echo is minutely faster than print and you should always use htmlentities on user submitted data to escape special chars as it reduces the risk of XSS and session hijacking. Quote Link to comment Share on other sites More sharing options...
Kane250 Posted March 31, 2009 Author Share Posted March 31, 2009 Ohh cool, this is a much better solution, thank you! Yeah, I'm still learning about security with forms...not looking forward to reg exps... ha Thanks again! Quote Link to comment Share on other sites More sharing options...
Andy-H Posted March 31, 2009 Share Posted March 31, 2009 NP http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax Tutorial by DarkWolf, should help alot with regex. Quote Link to comment 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.