Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Making A Value In A Textbox Stay
Feelay
post Mar 1 2008, 09:59 AM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



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 smile.gif


Thanks //Feelay
Go to the top of the page
 
+Quote Post
toby
post Mar 1 2008, 03:31 PM
Post #2


Super Member
Group Icon

Group: Members
Posts: 511
Joined: 29-September 06
Member No.: 16,228



In Javascript, there's history.back and history.go(N), eg -1.
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Mar 1 2008, 07:51 PM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 392
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



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.
Go to the top of the page
 
+Quote Post
jlhaslip
post Mar 2 2008, 01:48 AM
Post #4


Advanced Member
Group Icon

Group: Members
Posts: 187
Joined: 15-November 05
From: Inland from the Left Coast of Canada
Member No.: 9,627



Google "ullman redux sticky forms" for a php script and tutorial that retains the data in a form.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Mar 2 2008, 03:07 AM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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>
&lt;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,

This post has been edited by TavoxPeru: Mar 2 2008, 03:12 AM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting <enter> To \n In Textbox(2)
  2. Making My Album(3)
  3. Bbcode Help(9)
  4. Making Animated Gifs(5)
  5. Making A Link = Mysql_query(8)
  6. Making Something In Mysql Happen Only Once(10)
  7. Changing A Value From A Textbox(6)


 



- Lo-Fi Version Time is now: 13th October 2008 - 05:54 AM