?
Solved

how do I keep form field populated after using the back button?

Posted on 2008-10-09
7
Medium Priority
?
645 Views
Last Modified: 2012-06-21
I'm building a form in a custom Joomla component. It collects payment details and has a captcha image.
When the form is submitted and the captcha string is incorrect a message is displayed..."incorrect code please try again" and there's a button that takes the user back to re-enter the code.

<form>
 <input type=button value="Go back to payment form" onClick="history.go(-1)">
</form>

when you click this the form appears a gain but all the fields are empty.

How can I make it so that the field retain the information previously entered.

thanks
0
Comment
Question by:xoundboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
lightit earned 2000 total points
ID: 22680207

Maybe use sessions?

in your page with the al the fields, put this on top
<?php
session_start();
?>

in every value from a field you put this code:
 <?php echo $_SESSION["fieldname"];?>

In the page where you go to after the form is submitted you first do this, you register every session and give it a value

<?php
session_start;
@ session_register("fieldname1"); // The @-sign removes the error if this session is already registered
@ session_register("fieldname2");

$_SESSION("fieldname1") = $_POST["fieldname1"];
$_SESSION("fieldname2") = $_POST["fieldname2"];

// PUT HERE THE REST OF THE CODE
?>

You will see, after you returned to your previous page the fields will be filled with the value,
it is best that you destroy the sessions after the form has a succesfull submit, because otherwhise if the people come back at this page the fields will be still filled in, do that like this
<?php
session_start();
session_destroy();
?>

Sorry for bad english

Greetz
0
 
LVL 2

Author Comment

by:xoundboy
ID: 22682415
thanks

I tried that but I'm getting this error which I don't understand:

Fatal error: Can't use function return value in write context in /vservers/mydomain/htdocs/test/components/com_payment/form_action.php on line
0
 
LVL 2

Author Comment

by:xoundboy
ID: 22685066
let me clarify that last comment.

this line:

$_SESSION("students_name") = $_POST["students_name"];

 in the page that the form submits to is generating this error:

Fatal error: Can't use function return value in write context in /vservers/mydomain/htdocs/test/components/com_payment/form_action.php on line 19

 what is wrong with setting a session variable like this?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Assisted Solution

by:lightit
lightit earned 2000 total points
ID: 22685433
Sorry my bad!

$_SESSION["students_name"] = $_POST["students_name"];

That is the right way! It was already very late yesterday
0
 
LVL 2

Author Comment

by:xoundboy
ID: 22685760

I followed your instructions very carefully. It still doesn't work though. It could be something to do with the fact that the form is being included into a joomla index.php page, its URL being:

www.mydomain.com/index.php?option=com_payment

I tried dumping the conents of the session variable just before the form and it appears to be empty - hence the fields not being repopulated. The strange thing is though that if I run the same session dump script afterwards from a non index.php  location then the session is still alive and the values are still held there. This would imply that joomla's index controller is hiding the session variables from the form but without actually destroying them. It's very frustrating.

Anyone have any ideas? Anyone know the Joomla framework? This is the 1st time I'm developing a component for Joomla so it's all a bit strange.

HELP!
0
 
LVL 2

Author Comment

by:xoundboy
ID: 22693103
I've had another go at it and realised that I forgot to add one field to the list of session_register('fieldname"); 's. Now it works :)

0
 
LVL 2

Author Closing Comment

by:xoundboy
ID: 31504690
thanks very much - great answer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question