Feelay
Mar 1 2008, 09:59 AM
| | Hey!
I know it is possible, but I don't know how to do it. Anyone who know how I can make the following:
When a user type a message, and press Send, he will come to a page that will check the message. If an Error occur, the user must press a button, that will take him back to the message, and fix the error. but The problem is, that when the user press the button, his message is gone, and he must write it again. bad luck, if the message was long. Hope You undertsand what I want 
Thanks //Feelay |
Comment/Reply (w/o sign-up)
toby
Mar 1 2008, 03:31 PM
In Javascript, there's history.back and history.go(N), eg -1.
Comment/Reply (w/o sign-up)
turbopowerdmaxsteel
Mar 1 2008, 07:51 PM
While History.back should do it, on some ocasions the values of Textarea controls get reset. You can use cookies to save those data. When the user is re-directed back to the original page, load the contents from the cookies. Say you have a form (form.php) with two fields Name & Message & the form submits the data to your submit.php file. This file should validate the data and on error store the data as cookies to the browser along with a status flag that denotes whether the action was completed successfully or not. Now, when the user clicks on the Back button, user is re-directed to the form.php file which checks the value of the status flag and loads the contents from the cookies accordingly. Cookies could be avoided by using a different mechanism. The submit.php file should output the page with Back button as form. This form would contain the previously typed messages as hidden fields. On submit via HTTP POST (when user clicks on BACK button), these contents would be supplied to form.php which would load the values into the fields.
Comment/Reply (w/o sign-up)
jlhaslip
Mar 2 2008, 01:48 AM
Google "ullman redux sticky forms" for a php script and tutorial that retains the data in a form.
Comment/Reply (w/o sign-up)
TavoxPeru
Mar 2 2008, 03:07 AM
You can do it without using cookies, just using the superglobal array $_POST, try this and let me know if it is what you need. CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Making Values Stay</title> <script type="text/javascript"> function verifica() { if (document.a.text1.value=="") { alert("Error... Insert a text"); document.a.text1.focus(); return false; } return true; } </script> </head> <body > <?php $text1=(isset($_POST["text1"])) ? (string) trim($_POST["text1"]) : ""; $textarea1=(isset($_POST["textarea1"])) ? (string) trim($_POST["textarea1"]) : "";
if(isset($_POST["accept"])) { $text1=(string) trim($_POST["text1"]); $textarea1=(string) trim($_POST["textarea1"]); if(empty($textarea1)) { die("The textarea field was blank! <br /><br /><a href=\"java script:history.back();\">Press here to try again</a>"); } else { echo "submit successful"; exit(); } } else { ?> <table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td>TEST FORM</td></tr></table> <form name="a" method="post" onsubmit="return verifica();"> <table width="100%" border="0" cellpadding="2" cellspacing="4"> <tr> <td width="20%">TEXT VALUE</td> <td width="80%"><input type="text" name="text1" value="<?php echo $text1;?>" size="40" maxlength="80" onfocus="this.select()" /></td> </tr> <tr> <td width="20%">TEXT AREA VALUE</td> <td width="80%"><textarea name="textarea1" cols="50" rows="5"><?php echo $textarea1;?></textarea></td> </tr> <tr> <td width="100%" align="center" style="padding:10px 0px" colspan="2"> <input type="submit" name="accept" value="Save" > <input type="reset" name="cancel" value="Cancel" > </td> </tr> </table> </form> </body> </html> <?php } ?> Only for testing purposes i don't validate the submited data, so, remember to validate it before you insert to a database for example, one way to do this is by using the mysql_real_escape() php funciton. View it in action at Making values stay. Tested with Internet Explorer 6, Firefox 2.0.0.12 and Opera 9.26. Best regards,
Comment/Reply (w/o sign-up)
Feelay
Dec 26 2008, 03:26 PM
heh.. Long time ago I made this, but I figured it out yesterday XD The easiset thing that you can do, is.. CODE <form> <?php echo "<input type=\"textbox\" name=\"text\" value=\"{$_POST['text']}>"; ?> <input type="submit" name="submit"> </form> if you make the script check on the same page, and something goes wrong, the input of the text area/ box will be saved in a vvariable, and the variable will be the value of the box
Comment/Reply (w/o sign-up)
pyost
Dec 27 2008, 01:16 PM
You have to be careful, though. In case Magic Quotes is turned off (which is should be, a completely useless feature), all the data inside $_POST and $_GET arrays will not have escape quotes, apostrophes etc. If someone enters a value with quotes, you would get something like this: HTML <input type="textbox" name="text" value=""value"with quotes"> Needless to say, this is valid HTML  That is why it is necessary to use addslashes() - oh, and also, the input tag need to be closed: HTML <input type="textbox" name="text" value=""value\"with escaped quotes" />
Comment/Reply (w/o sign-up)
Feelay
Dec 27 2008, 01:19 PM
Thanks for the warning =D And I didn't know input tags had to be closed ._. I thought it was enuogh just to close the form tag. Anyways, Thanks =D //Feelay
Comment/Reply (w/o sign-up)
TavoxPeru
Dec 28 2008, 06:16 AM
Yes, input tags has to be closed as all the other empty xhtml tags like IMG or HR tags for example, especially if you want to validate your code. Now, the code showed by Feelay and pyost are INCORRECT, because as far as i know, the HTML and the XHTML specifications do not include an input tag of type TEXTBOX, so, the correct codes to use are: BTW, you should look into other ways for escaping strings if you will work with databases, because addslashes does NOT make your input safe for use in a database query! It only escapes according to what PHP defines, not what your database driver defines. For example, if you work with a MySql database it's recommended to use the mysql_real_escape_string() instead of using the addslashes() function. Therefore relying on addslashes is not a good idea at all and may make your code vulnerable to security risks like SQL Injection Attacks. Best regards,
Comment/Reply (w/o sign-up)
Feelay
Dec 28 2008, 12:28 PM
As far as I know, textbox is the type that right =S and I use it, and it works. And as far as I know, type="text" doesn't work =S and when handeling database data, I do use mysql_real_escape_string ((= But when making.. for example a contact script, that doesn't have anything to do with a database, I don' think it works  therefor, I use addslashes() But thanks for the warnings =) people not aware of it, may use your help ^^ //Feelay
Comment/Reply (w/o sign-up)
mastercomputers
Dec 31 2008, 09:45 AM
Just continuing with pyost. To retain the form fields is: CODE <input id="text" name="text" value="<?php if(isset($_POST['text'])) { echo htmlentities($_POST['text']); } ?>" /> This will convert any HTML elements like quotes and less-than/great-than signs to HTML representable code so it will still display properly on the page without messing it up, could possibly get away with htmlspecialchars but htmlentities covers a larger range of characters. Isset is to check if the variable exists to avoid warnings, which you would see if you had error_reporting(E_ALL | E_STRICT); If using htmlentities, you'll also need to reverse the effects too when using the data unless you can handle the conversions (which I don't recommend as it can make it harder and cause more problems). Cheers, MC
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : making, textbox, stay
- Changing A Value From A Textbox
or something. don't exactly how to explain. (6)
Making Something In Mysql Happen Only Once
(10) Hey! I know I am asking alot. But much is happening theese days. Sorry if I disturb with my
questions. The thing I am trying to do is: Ex. If the user becomes level 2, he should get 5 skill
points. I can't do this: CODE if($userlevel=5){ mysql_query("UPDATE user SET skillpoints
=$points+5");} because then it would update everytime the code was loaded. I hope you understand
what I am trying to do. If not, tell me /smile.gif" style="vertical-align:middle" emoid=":)"
border="0" alt="smile.gif" /> and i'll try to explain better. Thanks //Feelay....
Making A Link = Mysql_query
(8) Hey! I will try to make this as clear as possible. how can I make the following. I have a list,
of all members on my site. If I press on a members name(link), I will come to his profile. To come
to his profile, I need to get out some vaule from the database, but to get out some value from the
database, I must tell the code, how it should know who the user is (hard to understand?). To do
that, I must add a mysql_query in the code ( I think), like "SELECT user FROM dbname WHERE
user=link".. This is just how I think it works. I know it is kinda wrong.. but I don't k....
Making Animated Gifs
(5) Is it possible to make animated images using PHP's GD library? I've done searches, and I
can't find anything that explains it fully, or doesn't need you to download a special
program, which obviously, I couldn't use with Astahost. Can anyone help? I'm not aure how
animated gifs work, I don't know if all the frames are compressed within the .gif file as
separate images, or whether it's structured another way.....
Bbcode Help
Making BBCode (9) OK well I wanted to add some BBCode to my website but I ran into trouble. At first I was useing str_
replace() but that does not work if I am trying to make the
code. I think I would use preg_match but I am real confused. Could someone post the source code to
make: CODE Website Into: CODE Website Also how would I make the code tag so it
would replace all withen the two strings with [ and ] example CODE would print the
html CODE [b] [/b] Do you get what I am trying to do? Thanks, Sparkx Note: I had
to take out so....
Making My Album
problems with rights (3) We have to make something in PHP for school, so I decided to make a complete photoalbum. One of the
things that it can is creating and storing thumbnails, but here is where the problems start. The
thumbnails have to be stored in a subfolder called 'thumbnails', if this folder doesn't
exist, my script creates this folder and everything works like it is supposed to be. But it
doesn't do that the way I want. The folder is made with: CODE mkdir($thumbnail_folder,
0777); but when I check it via FTP, it is set to 755. Even worse is that I can't acce....
Converting <enter> To \n In Textbox
(2) I'm making a script that emails data and in the message box, I need all to be converted to \n
so when it is mailed, it will format properly into: This is a test When submitted, it would be
turned into: This \n is \n a \n test So that it can easily be mailed. Or does PHP do this
automatically? Thanks! F....
Logging Items Entered Into A Textbox
(2) I'd like to have a log of items entered into a search box on my site. How can I do this so it
will write to a text file but not interfear with search operations? Thanks! F....
How To Make Chat Room
help me in making it (1) i need the code of making chatroom but plzzz i need it cute chat room /tongue.gif"
style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> , and it musnt be by java ,
if you know any website that make chatrooms free plz replay with the website /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
Notice
from m^e:
Who the hell approved this post? This is a question - and that too posted in
the Howtos & Tutorials. How did this get approved ? Moved to right forum.
....
Looking for making, textbox, stay
|
See Also,
*SIMILAR VIDEOS*
Searching Video's for making, textbox, stay
|
advertisement
|
|