I am developing my form into a captcha secured form and I used header() function if the user didn't put the verification code properly and still when the user go back to the form page the filled he have filled have still remained. In addition, users are usually submitting multiliner texts in the textbox so I used the str_replace() function to make all \n into %n% to prevent an error in the header function whenever the form is submitted. my script is: -
// load the variables form address bar
-
$category = $_REQUEST["jokecategory"];
-
$title = $_REQUEST["joketitle"];
-
$verif_box = $_REQUEST["verif_box"];
-
$text = $_REQUEST["joke"];
-
-
// remove the backslashes that normally appears when entering " or '
-
$MyTitle = addslashes($_POST[title1]);
-
$MyText = addslashes($_POST[text1]);
-
- $text = str_replace("\n", '%n%', $text);
-
-
// check to see if verificaton code was correct
-
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
-
-
$q1 = "insert into dd_items set
-
-
ItemTitle = '$MyTitle',
-
-
ItemCategory = '$MyCategory',
-
-
ItemSubcategory = '$MySubcategory',
-
-
ItemText = '$MyIn|$MyText',
-
-
Contributor = '$_SESSION[username]',
-
-
DateAdded = '$t' ";
-
-
-
-
mysql_query($q1) or die(mysql_error());
-
-
-
-
header("location:test.php");
-
-
exit();
-
-
} else {
-
// if verification code was incorrect then return to contact page and show error
-
$text = str_replace("%n%", '\n', $text);
-
header("Location:".$_SERVER['HTTP_REFERER']."?jokecategory=$category&joketitle=$title&joke=$text&wrong_code=true");
-
-
exit;
-
}
-
Now problem is that, I don't know where or how to reverse $text = str_replace("\n ", '%n%', $text); function in the textbox so whenever the user entered a wrong verification code the \n will not appear neither the %n%, it will be automatically put in the next line inside the textbox. Any ideas? Please see the bolded lines, it is where I put the functions and tried to reverse it yet if was a failure.
4 3072 code green 1,726
Recognized Expert Top Contributor
PHP does not recognise \n within single quotes.
It needs to be within double quotes. "\n"
But instead of converting backwards and forwards why not store the original?
Also, by re-arranging your logic you could improve your efficiency more.
What do you mean store the original? You mean I don't have to use the str_replace()? If that so, I will have an error "Warning: Header may not contain more than a single header, new line detected." if the form is submitted because the user may have entered more than one line in the textbox. That is why the solution I thought is to replace every "\n" into "%n" so that the server will not confused of the new lines. I said earlier I used the header() function. About re-arranging the logic, the script I posted is stripped just to make it simple to show my problem. :]
To see what I am doing, please click here . If the people entered more than one line in the textbox and able to provide the correct verification number, there's no problem at all but if the user entered a wrong verification number and has more that one line in the textbox, the "\n" actually in the textbox instead to make a new line.
I hope this makes clearer about my problem. :)
code green 1,726
Recognized Expert Top Contributor
What do you mean store the original?
[PHP]$origText = $text;
$text = str_replace("\n ", '%n%', $text);[/PHP]
You mean I don't have to use the str_replace()?
Not twice no.
I am sorry but you lose me after this but the idea is you use $origtext with the error and $text when OK;
I found the solution now! Wooohoo! What I did was to put this codes inside the textarea: -
<?php
-
$text = $_GET['joke'];
-
$text = str_replace("%n%", "\n", $text);
-
echo "$text";
-
?>
-
Thanks for the help guys! ^^
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Hugo Coolens |
last post by:
I need to use the str_replace function for a php-script which works
together with html/javascript.
In the script I have to perform things like:
$arabic=str_replace ("'","\'", $row);
$arabic=str_replace ("sh", "\š", $row);
the second line works perfectly, however I can't make the first one
work, it should replace a single quote with a quote preceded by a
backslash. I presume I have to escape some characters to make this
happen however...
|
by: barry |
last post by:
I am using the following code in a textbox:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
Dim txt As TextBox = CType(sender, TextBox)
txt.Text = txt.Text.ToUpper
End Sub
|
by: Tim Marshall |
last post by:
I use Terry Kreft's & Stephen Lebans colour dialog procedures for users
to pick colours for various control properties in certain apps.
Is there a way to take the colour code that is displayed in a
backcolor/forecolor/etc property and calculate the "reverse colour"? In
other words, If a user picks 255 (red) for a control backcolor, I'd like
to be able to calculate the opposite or negative of that colour and
assign the control's...
|
by: marcomputers |
last post by:
Hi,
I'm trying to automatically update an existing rss podcast file using
php and the str_replace function.
Every time I add a media file, it should read the .rss file into a
string, take the closing </channel> and </rss> tags out of it, and add
the new rss file info to the end of the existing string, writing it
back to the rss file. However, str_replace will not replace the
</channel> and </rss> tags with ' '. I'm new to php, any help...
|
by: Brad Everman |
last post by:
Something simple, perhaps someone can shed some light.
I have an array of paragraphs of text and am replacing some of the text
using str_replace().
Ex.
function addGraphic($numGraphic){
return("this is graphic $numGraphic");
| |
by: kencana |
last post by:
Hi all,
I got a doubt about the str_replace function.
<?php
$string="avenue 1, ave 1";
$words=str_replace ("ave","avenue", $string);
echo $words;
?>
|
by: arnuld |
last post by:
i have created a solutions myself. it compiles without any trouble
and runs but it prints some strange characters. i am not able to find
where is the trouble.
--------------------------------- PROGRAMME
--------------------------------
/* K&R2 section 1.9
exercise 1.19
|
by: steezli |
last post by:
Hi,
Brand new to VB.NET and I'm having a problem figuring out this program. I'll try and be descritive as possible.
I have to create a Windows application that contains a single top-level form with two textboxes on it, on positioned above the other. As each character is entered into the upper textbox, the string that has been entered into the upper textbox must appear in the lower textbox, but in reverse. If the input field contains...
|
by: jodleren |
last post by:
Hi all
I have text area, where I can edit files - but I have to correct the
returned data, for that I use
$content=str_replace('\"', '"', $content);
and
$content=str_replace('\\', '\', $content);
by some reason the latter one causes an error: syntax error,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |