[SOLVED] Strange error with $_POST

This is a discussion on "[SOLVED] Strange error with $_POST" within the PHP Forum section. This forum, and the thread "[SOLVED] Strange error with $_POST are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 13th, 2007, 15:27
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
[SOLVED] Strange error with $_POST

Before anyone says anything about using tables for layout, it's not my form and I am going to convert it to css when it works properly

Anyway, here is the problem. I have a BBcode form editor and it all works (well the other version I have does which hasn't got these changes).

When the user clicks on the preview button, I want the BBCode converted to html and it output so I can see what it looks like and below, display the form with the message and BBcode still intact, much like you see here when you preview a post.

When the user clicks on the post button, I want to see the message but wthout any formatting so it displays the message complete with BBcode (this is going to be stored in database in case of later editing).

The problems are when the user clicks on the post button, what is output to the browser is Post (which is the value of the Post submit button)

Also this used to work but trying it like this doesn't work anymore. When i preview the message, Bold, Italic and Underline doesn't work whereas the size, color, url etc still work.

Any ideas how I can get this to work?

PHP: Select all

<?php
function BBCode($Text)
       {
         
// Replace any html brackets with HTML Entities to prevent executing HTML or script
            // Don't use strip_tags here because it breaks [ url ] search by replacing & with amp
            
$Text str_replace("<""&lt;"$Text);
            
$Text str_replace(">""&gt;"$Text);
            
// Convert new line chars to html <br /> tags
            
$Text nl2br($Text);
            
// Set up the parameters for a URL search string
            
$URLSearchString " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
            
// Set up the parameters for a MAIL search string
            
$MAILSearchString $URLSearchString " a-zA-Z0-9\.@";
            
// Perform URL Search
            
$Text preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/"'<a href="$1" target="_blank">$1</a>'$Text);
            
$Text preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])"'<a href="$1" target="_blank">$2</a>'$Text);
            
//$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
            // Perform MAIL Search
            
$Text preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])"'<a href="mailto:$1">$1</a>'$Text);
            
$Text preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/"'<a href="mailto:$1">$2</a>'$Text);
         
            
// Check for bold text
            
$Text preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$Text);
            
// Check for Italics text
            
$Text preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$Text);
            
// Check for Underline text
            
$Text preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$Text);
            
// Check for strike-through text
            
$Text preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$Text);
            
// Check for over-line text
            
$Text preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);
            
// Check for colored text
            
$Text preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);
            
// Check for sized text
            
$Text preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1\">$2</span>",$Text);
            
// Check for font change text
            
$Text preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);
            
// Declare the format for [ code ]  layout
            
$CodeLayout '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="quotecodeheader"> Code:</td>
                                </tr>
                                <tr>
                                    <td class="codebody">$1</td>
                                </tr>
                           </table>'
;
            
// Declare the format for [ quote ] layout
            
$QuoteLayout '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="quotecodeheader"> Quote:</td>
                                </tr>
                                <tr>
                                    <td class="quotebody">$1</td>
                                </tr>
                           </table>'
;
                     
            
// Check for [ quote ] text
            
$Text preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout"$Text);
         
            
// Images
            // [img]pathtoimage[/img]
            
$Text preg_replace("/\[img\](.+?)\[\/img\]/"'<img src="$1">'$Text);
         
            
// [img=widthxheight]image source[/img]
            
$Text preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/"'<img src="$3" height="$2" width="$1">'$Text);
         
           return 
$Text;
      }
$unformatted $_POST['post'];
$text BBCode($_POST['post']);
if (isset(
$_POST['preview'])) {
   
//do something
   
echo $text;

else
if (isset(
$_POST['post'])) {
   
//do something
   
echo "Done it";
   echo 
nl2br($unformatted);
   exit;
}
?>
<html><head>
<title>Editor</title>
<script src="editor.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head><body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="editform" onsubmit="return checkForm(this)">
<table id="editform">
<tr>
        <td colspan="2" id="header">Post a new message</td>
</tr>
<tr id="subject">
        <td>Subject:</td>
        <td><input type="text" name="subject" size="50" class="form_elements_text"/></td>
</tr>
<tr>
        <td rowspan="2" id="smilies">Smilies
                <a href="javascript:smilie(':)')">
                        <img src="smile.gif" alt="smile" title="smile" /></a>
                <a href="javascript:smilie(':D')">
                        <img src="biggrin.gif" alt="big grin" title="big grin"/></a>
                <a href="javascript:smilie(':p')">
                        <img src="razz.gif" alt="razz" title="razz" /></a></td>
        <td>
                <input type="button" class="button" value="bold" name="bold" onclick="javascript:tag('b', '[b]', 'bold*', '[/b]', 'bold', 'bold');" onMouseOver="helpline('bold')" />
                <input type="button" class="button" value="italic" name="italic" onclick="javascript:tag('i', '[i]', 'italic*', '[/i]', 'italic', 'italic');" onMouseOver="helpline('italic')" />
                <input type="button" class="button" value="underline" name="underline" onclick="javascript:tag('u', '[u]', 'underline*', '[/u]', 'underline', 'underline');" onMouseOver="helpline('underline')" />
                <input type="button" class="button" value="quote" name="quote" onclick="javascript:tag('q', '[quote]', 'quote*', '[/quote]', 'quote', 'quote');" onMouseOver="helpline('quote')" />
                <input type="button" class="button" value="mail" name="mail" onclick="javascript:tag('mail', '[mail]', 'mail*', '[/mail]', 'mail', 'mail');" onMouseOver="helpline('mail')" />
                <input type="button" class="button" value="url" name="url" onclick="javascript:tag('url', '[url]', 'url*', '[/url]', 'url', 'url');" onMouseOver="helpline('url')" />
                <input type="button" class="button" value="img" name="img" onclick="javascript:tag('img', '[img]', 'img*', '[/img]', 'img', 'img');" onMouseOver="helpline('img')" />
                <br />
                Font size: <select name="fontsize" onChange="font('[size=' + this.form.fontsize.options[this.form.fontsize.selectedIndex].value + ']', '[/size]'); this.selectedIndex=2;" onMouseOver="helpline('fontsize')" class="form_elements_dropdown">
                                <option value="xx-small" >Tiny</option>
                                <option value="x-small" >Small</option>
                                <option value="normal" selected >Normal</option>
                                <option value="large" >Large</option>
                                <option value="x-large" >Huge</option>
                        </select>
                Font color: <select name="fontcolor" onChange="font('[color=' + this.form.fontcolor.options[this.form.fontcolor.selectedIndex].value + ']', '[/color]'); this.selectedIndex=0;" onMouseOver="helpline('fontcolor')" class="form_elements_dropdown"  >
                                <option value="black" style="color:black">Black</option>
                                <option value="silver" style="color:silver">Silver</option>
                                <option value="gray" style="color:gray">Gray</option>
                                <option value="maroon" style="color:maroon">Maroon</option>
                                <option value="red" style="color:red">Red</option>
                                <option value="purple" style="color:purple">Purple</option>
                                <option value="fuchsia" style="color:fuchsia">Fuchsia</option>
                                <option value="navy" style="color:navy">Navy</option>
                                <option value="blue" style="color:blue">Blue</option>
                                <option value="aqua" style="color:aqua">Aqua</option>
                                <option value="teal" style="color:teal">Teal</option>
                                <option value="lime" style="color:lime">Lime</option>
                                <option value="green" style="color:green">Green</option>
                                <option value="olive" style="color:olive">Olive</option>
                                <option value="yellow" style="color:yellow">Yellow</option>
                                <option value="white" style="color:white">White</option>
       </select>
                                <br />
                <input type="text" name="helpbox" size="75" class="helpbox" readonly="readonly"/>
                </td>
</tr>
<tr>
                <td>
                Post:<br />
                <textarea rows="10" cols="50" name="post" class="form_elements_text"><? echo $unformatted?></textarea>
                </td>
</tr>
<tr>
                <td colspan="2" id="post">
                <input type="submit" name="post" value="Post" class="button" />
                <input type="submit" name="preview" value="Preview" class="button"/>
                <input type="reset" value="Start over" class="button" onclick="javascript:confirm_reset();"/>
                </td>
</tr>
</table>
</form>
</body></html>
Reply With Quote

  #2 (permalink)  
Old Oct 13th, 2007, 16:26
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: Strange error with $_POST

I have made some progress by keeping the files seperate.

I have the form whcih takes input from the user. It then calls bbcode.php and it checks which button has been pressed.

If the preview button is pressed, it converts the bbcode to html and redisplays the form but if the post button has been pressed, I still get "Post" output to the browser and not the unfrmatted text
Reply With Quote
  #3 (permalink)  
Old Oct 13th, 2007, 17:12
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: Strange error with $_POST

Got it working....turned out the textarea and the submit button had the same name
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Getting the &quot;Microsoft JET Database Engine error '80040e14'&quot; error. VegaLA Classic ASP 3 Jan 26th, 2008 00:12
Another strange microsoft error Daniel Webforumz Cafe 9 Oct 25th, 2007 13:59
Strange CF Error tallgal2007 Other Programming Languages 0 Jun 8th, 2007 12:32
Weird $_POST error Blake121 PHP Forum 3 Jun 6th, 2007 22:26
$_POST Problem Bradster PHP Forum 3 May 30th, 2007 16:13


All times are GMT. The time now is 07:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43