Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

[solved] users can know go back and alter information have a look fully tested

Recommended Posts

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]

Share this post


Link to post
Share on other sites
example_result.php: [code]<?php
session_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]<?php
session_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.

Share this post


Link to post
Share on other sites
can you kindly exsplain what the code is doing and what is unserialize and serialize

cheers.

Share this post


Link to post
Share on other sites
serialize sets the varable  and unserialize wakes it up

i read the manual but surly a session can do the same as the above posted code.

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
why can we not do it this way please

[code]
<?php
session_start();

if($description=="none"){

$_SESSION['data'] = $data;
echo "sorry try agin <br>

<a href='example.php'>try agin please</a>";

}
?>
[/code]

[code]
<?php
session_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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
this is the correct way

cheers.


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]

Share this post


Link to post
Share on other sites
heres an example of a code that lets your users go
back 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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.