...

View Full Version : Form Post - Slashes - Help!



curb
05-03-2006, 07:29 AM
Hi, I'm very new with php so it might be hard for me to explain what I'm trying to say and do. On the page "site.php", there's a textarea with a html code to google inside it. When someone submits that form, it'll send them to preview.php with the hardlink outside the textarea AND the source code to the hardlink inside the textarea.

The problem is that preview.php is giving out slashes:


<a href=\"http://www.google.com\">google</a>

Code:

site.php
<form action="preview.php" method="post">
<input type="hidden" name="action" value="preview">
<textarea class="hidden" name="preview">
<a href="http://www.google.com">google</a>
</textarea>
<input type="submit" name="view" value="Preview">
</form>


preview.php
<? echo ''.$_POST['preview'].'';?>
<br><br>
<textarea><? echo ''.$_POST['preview'].'';?></textarea>

I hope someone could help me out.

raf
05-03-2006, 08:38 AM
welcome here!

use


stripslashes($_POST['preview'])

to remove them

manual: http://uk.php.net/manual/en/function.stripslashes.php

curb
05-03-2006, 08:43 AM
welcome here!

use


stripslashes($_POST['preview'])

to remove them

manual: http://uk.php.net/manual/en/function.stripslashes.php


So do I do this?:

<? echo stripslashes($_POST['preview']);?>
<br><br>
<textarea><? echo stripslashes($_POST['preview']);?></textarea>

raf
05-03-2006, 09:25 AM
or you coud use


<?php
$post_preview_url = stripslashes($_POST['preview']);
echo $post_preview_url, '<br /><br /><textarea>', $post_preview_url ,'</textarea>';
?>

--> set the variables at the top of your script is more transaprant and easier to maintain + you only need to process them once
--> don't use shorttags (<? and ?>) since they wount work on all servers. use <?php and ?>
--> don't drop in and out of php mode, just echo out the html in single quoted strings
--> use echo with multiple arguments, concatinated with ',' because this uses less runtime resources then an echo 'string1' . 'string2' etc

curb
05-03-2006, 09:39 AM
Wow that's a lot more convienant. Thanks a lot Raf for your help.

degsy
05-03-2006, 03:33 PM
If you are wanting a more advanced text area then look into using a Rich Text Editor such as KTML Lite or FCKEditor

raf
05-03-2006, 03:37 PM
Wow that's a lot more convienant. Thanks a lot Raf for your help.you're welcome:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum