tags:

views:

69

answers:

2

I have a form which allows the user to enter embed code from youtube.

I also have an edit form which will allow the user to edit the size of the embed code (like the width and height: <object width="425" height="344">..)

I used

<textarea name="oldvideo" id="oldvideo"><?php echo embed; ?></textarea>

However when I submit the form, and get the edited embed code using

echo $_POST['oldvideo'];

I can't get the embed code from the textarea.

A: 

I'd guess you just need echo htmlentities($embed);, else you output the old html snippet raw in between the <textarea> tags and it just goes ignored.

mario
When I echo $_POST['oldvideo']; it still won't show anything.
anonymous
Then theres probably a problem with your form. No data is being sent
Mark
@anonymous: Do a print_r($_POST); and a print_r($_REQUEST) instead. If neither reveals anything, then the problem is elsewhere. Use Firefox+Firebug to debug it then, if you don't want to show the complete code.
mario
Is there an opposite to htmlentities()?I understand that this function changes "<" to "<" etc...How do I return them to their normal text equivalents?
anonymous
@anonymous: No there is no default reversal function in PHP. You normally don't need it. In your example the browser will return the raw text, that is `<` instead of `<`, when it sends the form data back.
mario
A: 

First, is your form set up right? In order to get data from $_POST you have to have:

<form action="" method="post">
...your form goes here...
<input type="submit" value="Whaver you want the button to say goes here">
</form>

The 'action' attribute is the page that will load when the user hits the submit button, if you define it to be empty ("") then it will just reload this same page.

Then if you have your form element like so:

<textarea name="oldvideo" id="oldvideo"><?php echo $embedCode; ?></textarea>

...then when the user types something into the textarea and hits submit it will be saved to $_POST['oldvideo'].

Whatever you have saved to the variable $embedCode will just be sitting in the textarea as it's default value until someone types in anything else. If you don't need them to have a default value then you could leave that out.

Lastly, you should make sure your code is setup like so...

if( isset($_POST['oldvideo'] ) {
    $embedCode = $_POST['oldvideo'];
    ...the rest of your code that makes use of the user-submitted value...
} else {
    $embedCode = "The Default Value for Embed Code Goes Here";
}

If you try to use $_POST['oldvideo'] without putting inside an if(isset()) block, then you'll get an error when you try to load the page.

Hope this helps, but it would also be easier to help you if you gave us a little more detail about your problem!

Andrew