Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 02:56 PM

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
<?php session_start();

if($description=="none"){

echo "sorry try agin <br>

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

}
?>


example.php
<?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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 August 2006 - 03:00 PM

example_result.php:
<?php
session_start();

if($description=="none"){

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

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

}
?>

example.php:
<?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>

This should do it.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 03:04 PM

can you kindly exsplain what the code is doing and what is unserialize and serialize

cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 03:08 PM

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.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 August 2006 - 03:10 PM

Sure. Serialize makes you able to store an array as a string, eg
array('description' => 'hello');
would become
a:1:{s:11:"description";s:5:"hello";}

Unserialize reverses the process.

This line:
$_SESSION['data'] = serialize($_POST);
serializes the POST array and stores it as a session variable called data.

This line (in the other file):
$data = unserialize($_SESSION['data']);
defines the array $data the session variable data unserialized.

This:
<?php echo $data['description']; ?>
simply echoes the value of $data['description']

EDIT:

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

The code did use sessions ;)

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 03:17 PM

why can we not do it this way please

<?php
session_start();

if($description=="none"){

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

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

}
?>

<?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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 August 2006 - 03:20 PM

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.

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 03:22 PM

i dont no my self testing ok and thank you.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 04:25 PM

this is the correct way

cheers.


test.php


<?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>



test_result.php
<?php session_start();


$des=$_SESSION['des']=$description;


echo "sorry try agin <br>

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

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 04:41 PM

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.


<?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!";

}

?>


<?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>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users