redarrow Posted August 20, 2006 Share Posted August 20, 2006 I want to be able to let users go back and alter there text without them lossing it if they got an error.advance thank you.example_result.php[code]<?php session_start();if($description=="none"){echo "sorry try agin <br><a href='example.php'>try agin please</a>}?>[/code]example.php[code]<?session_start();<html><head></head><title>test form</title><body><form method="POST" action"example_result.php"><br>description please<textarea name="description" cols="200" rows="200"></taxtarea><br><input type="submit" name="submit" value="send"></td></table></form></html>[/code] Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/ Share on other sites More sharing options...
Daniel0 Posted August 20, 2006 Share Posted August 20, 2006 example_result.php: [code]<?phpsession_start();if($description=="none"){$_SESSION['data'] = serialize($_POST);echo "sorry try agin <br><a href='example.php'>try agin please</a>";}?>[/code]example.php: [code]<?phpsession_start();$data = unserialize($_SESSION['data']);?><html><head></head><title>test form</title><body><form method="POST" action""<br>description please<textarea name="description" cols="200" rows="200"><?php echo $data['description']; ?></taxtarea><br></td></table></form></html>[/code]This should do it. Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77566 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 can you kindly exsplain what the code is doing and what is unserialize and serializecheers. Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77570 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 serialize sets the varable and unserialize wakes it upi read the manual but surly a session can do the same as the above posted code. Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77572 Share on other sites More sharing options...
Daniel0 Posted August 20, 2006 Share Posted August 20, 2006 Sure. Serialize makes you able to store an array as a string, eg [code]array('description' => 'hello');[/code] would become [code]a:1:{s:11:"description";s:5:"hello";}[/code]Unserialize reverses the process.This line: [code]$_SESSION['data'] = serialize($_POST);[/code] serializes the POST array and stores it as a session variable called data.This line (in the other file): [code]$data = unserialize($_SESSION['data']);[/code] defines the array $data the session variable data unserialized.This: [code]<?php echo $data['description']; ?>[/code] simply echoes the value of $data['description'][b]EDIT:[/b][quote author=redarrow link=topic=104950.msg418893#msg418893 date=1156086499]i read the manual but surly a session can do the same as the above posted code.[/quote]The code [i]did[/i] use sessions ;) Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77574 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 why can we not do it this way please[code]<?phpsession_start();if($description=="none"){$_SESSION['data'] = $data;echo "sorry try agin <br><a href='example.php'>try agin please</a>";}?>[/code][code]<?phpsession_start();$data = ($_SESSION['data']);?><html><head></head><title>test form</title><body><form method="POST" action""<br>description please<textarea name="description" cols="200" rows="200"><?php echo $data['description']; ?></taxtarea><br></td></table></form></html>[/code] Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77577 Share on other sites More sharing options...
Daniel0 Posted August 20, 2006 Share Posted August 20, 2006 I couldn't remember if a session variable could contain an array, and I didn't bother to test it. If it works, then just do that. Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77578 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 i dont no my self testing ok and thank you. Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77579 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 this is the correct waycheers.test.php[code]<?php session_start();?><html><head></head><title>test form</title><body><form action="test_result.php" method="post"><br>description please<textarea name="description" cols="20" rows="20"><? echo $des; ?></textarea><br><input type="submit" name="submit" value="submit"></body></form></html>[/code]test_result.php[code]<?php session_start();$des=$_SESSION['des']=$description;echo "sorry try agin <br><a href='test.php'>try agin please</a>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77620 Share on other sites More sharing options...
redarrow Posted August 20, 2006 Author Share Posted August 20, 2006 heres an example of a code that lets your users goback and alter the incorrect form fields but with there existing form entry to save them time.good luck all.fully tested copy the code make the relevent pages test.php and test_result.php and enter 1234 in the form your get an error telling the user that the entry was wrong with a link. use the link to go back to the entry form page the user will see there entry in tact and know can alter to the correct entry. [code]<?php session_start();$des=$_SESSION['des']=$description;if(!eregi("^[a-zA-z]{1,100}$",$description)){echo "sorry try agin <br><a href='test.php'>try agin please</a>";}else{echo "correct words no numbers remeber that next time ok!";}?>[/code][code]<?php session_start();?><html><head></head><title>test form</title><body><form action="test_result.php" method="post"><br>description please<textarea name="description" cols="20" rows="20"><? echo $des; ?></textarea><br><input type="submit" name="submit" value="submit"></body></form></html>[/code] Link to comment https://forums.phpfreaks.com/topic/18104-solved-users-can-know-go-back-and-alter-information-have-a-look-fully-tested/#findComment-77626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.