473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to show the warning after we redirect the user to the same page?

I have searched in google about my problem.
But I don't get the best solution for my need.

My Problem is:
I create a form with TextBox Name, TextBox Message, Submit button, and it use POST method. I want form'process done in the same page.

After the user input data to TextBox Name and TextBox Message and pressed submit button,it send data well.

If the user input data to TextBox Message with word' length more than 100 words, it will display warning.

But if the user click refresh or F5 or Back button, in Firefox,it will display resend confirmation. So, I add line:
header("location: thispage.php");

to prevent the browser show resend confirmation.
But, as the result,
if the user input data to TextBox Message with word' length more than 100 words, it will not display warning.



Could you help me to solve my problem for it can show warning again with your script..Thank you for your kind attention..
Best regards,

Fritz Gamaliel


Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. if(isset($_POST['BtnShout']))
  3. {
  4.     //SEND COMMENT AND SHOW IT TO SCREEN PROCESS
  5.     //STEP1.GET DATA
  6.     $vName=$_POST["TxtName"];
  7.     $vMessage=$_POST["TxtMessage"];
  8.  
  9.     //STPE2.COMMENT MUST < 100 WORDS
  10.     if(strlen($vMessage)>100)
  11.     {
  12.         $warning = "Comment must < 100 words.";
  13.     }
  14.     header("location: thispagename.php");
  15. }
  16. ?>
  17.  
  18. <HTML>
  19. <TITLE> MyWEB </TITLE>
  20. <head></head>
  21.  
  22. <body>
  23. <form action="" method="post">
  24. Name:
  25. <input type="text" name="TxtName" maxlength=6 size=20/><br>
  26. Message
  27. <textarea name="TxtMessage" cols="50" ></textarea><br>
  28. <input type="submit" name="BtnShout" value="shout!"/>
  29. </form>
  30.  
  31. <?
  32. echo $warning."<BR>";
  33. ?>
  34.  
  35. </BODY>
  36. </HTML>
Aug 25 '10 #1
4 1885
zorgi
431 Expert 256MB
If you want to count words than use str_word_count. strlen returns olnly string length.

Your logic is also flawed. This is what you are saying in your code:
If length of $vMessage is less than 100 than set $warning = "Comment must < 100 words."

And you probably want to say:
If length of $vMessage is greater than 100 than set $warning = "Comment must < 100 words."

Also you are executing redirection whenever your form gets submitted. You should condition that line of code somehow. Have a look at simple elseif/else if
Aug 25 '10 #2
Pardon me if I don't ask clearly. But my problem not like that.

My Problem is:
I create a form with PHP.
My Form has TextBox Name, TextBox Message, Submit button.
My Form use POST method.

The User input data into TextBox Message then click Submit button. It will process the Form.

Now, the user input data into TextBox Message with length > 100 words. then, click submit. In the screen, will appear "Comment must < 100 words". After that, the user click Refresh button or click Back button in the browser or click F5. In Firefox, it will rise resend confirmation. So, I add line:

header("Location:thispagename.php");

It will prevent the browser show resend confirmation.
But as the result, when the user input data into TextBox Message with length > 100 words, it will not show "Comment must > 100 words".

How to fix my code? Thank you..
Note: I want to process my form only in one page.
Aug 25 '10 #3
zorgi
431 Expert 256MB
I am sorry but I have given you the answer. I only forgot to mention that with forms, its good practice to redirect after successful submission to avoid multiple submitting of the same data.

The logic:

Expand|Select|Wrap|Line Numbers
  1.     if(//ERRORS ON THE FORM)
  2.     {
  3.         /*Handle errors*/
  4.     }else{//NO ERRORS ON THE FORM
  5.         /*use the data and redirect*/
  6.     }
  7.  
Aug 25 '10 #4
but how to impelement your logic to my code above?

What you mean with Form error?
Because There is no error in my code.

I just want the web browser not show resend confirmation if the user click F5 on keyboard or click refresh button after submit a form.
I have solve this problem by add line:
header("Location:thispagename.php");
and it successfull.
But as the result, the warning not appear because of that line. Now, I just want to show it warning without replace that line...

But, how?thank you.
Aug 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: sampriti | last post by:
Hi, Is it possible to redirect user to same webserver until his session ends? Thanks in advance
5
by: Nazir | last post by:
I am trying to do something pretty simple - but can't see how it can be done in ASP.NET. I have an aspx web page with a form which opens up a new window. The web page uses code behind to build...
3
by: blu3g85 | last post by:
how to redirect a page? as in after a few sec, the page will auto direct u to another page. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----...
5
by: darrel | last post by:
I have a 'cancel' button that should reload the current page. Ie, reset the page back to it's initial state. Is the best way to do this to simply have the event handler for that button redirect...
0
by: underground | last post by:
I have a question more so I need a example of how to achieve this type of php function. I don't have any script I been playing around with the idea in my head and need some expert opinion as well...
1
by: Jon Paal | last post by:
what is property to redirect user after successful login ? <asp:Login ID="Login1" runat="server" ?????
2
windows_mss
by: windows_mss | last post by:
hi Programmers, In course of my project now i facing an proble that i have to Redirect the page to some other Page after the Default Session Time Expire <sessionState ...
17
by: jerrydigital | last post by:
Hello, I have an edit user page that allows the user to view their user information and make changes if possible. I have a simple html login page that directs to an asp page called edituser.asp...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
8
luckysanj
by: luckysanj | last post by:
Dear Sir, How can i redirect index page to wwx.site.com/me/index.php. I have not fineshed front index page work so now i want to redirect this page to my personal information which is located...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.