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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.