Jump to content

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


redarrow

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]
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.
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 ;)
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]
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]
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]

Archived

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

×
×
  • Create New...

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.