开发者

embed code in php

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 e开发者_运维知识库mbed 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.


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜