Jump to content

Pass text from a div?


Kane250

Recommended Posts

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!

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

<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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.