PDA

Click to See Complete Forum and Search --> : Swapping echo between pages


bharanidharanit
Feb 2nd, 2010, 11:39 PM
Hello,
In my application with the loginform.php, i am setting the action property of the form to be posted to checklogin.php, and what i need is, if the login fails i want to display the error messages in loginform itself. (error messages -> am using echo to display error messages in checklogin.php)
<form method="post" action="checklogin.php" name="loginform">

kows
Feb 2nd, 2010, 11:59 PM
you should post the form to itself instead of posting it to another script. do the validation at the beginning of your script so that you know whether or not to display errors.

bharanidharanit
Feb 3rd, 2010, 12:43 AM
ya thankyou this may works, but i am having all of scripts in a seperate php page, loginpage, register page etc. all will check from checklogin.php only. So i dont want the page to be posted to itself. Is there any other way to do this?
Thankyou

gmiller
Feb 3rd, 2010, 05:01 AM
I think this code will work for transferring data from one page to another. <form method="post" action="checklogin.php" name="loginform">

bharanidharanit
Feb 3rd, 2010, 05:51 AM
ya that wil works, but all the echo in the checklogin.php will be echoed there, but i want to be echoed in the loginform.php page itself.

kows
Feb 3rd, 2010, 11:01 AM
you can't have your checklogin file echo stuff out on your loginform page. they're two separate files.

having a registration page post to "checklogin" is a little illogical; I would still suggest separating these by doing what I said in my first post -- your register form should post to itself and all of the registration validation should be in that file, and your login form should post to itself and all of the login validation should be in that file. this would make maintenance much easier, too.

the only other easy way you could do this is to redirect back to the login/registration forms from the checklogin file and add a query string that tells you the errors. this is really sort of an ugly hack, though, and I wouldn't suggest it unless you're absolutely dead set on not separating things.

visualAd
Feb 4th, 2010, 06:50 AM
the only other easy way you could do this is to redirect back to the login/registration forms from the checklogin file and add a query string that tells you the errors. this is really sort of an ugly hack, though, and I wouldn't suggest it unless you're absolutely dead set on not separating things.

The ugly way is submitting the form to itself, as this can cause resubmission problems if the user refreshes the page. The preferred way of doing this is as follows:


Submit your form.php pages to processing page form_input.php. Form.php should include placeholders for the error messages and previously entered values. E.g.:

<div><?php echo(htmlspecialchars(@$data['name']['msg'])) ?></div>
<div><input name="name"
value="<?php echo(htmlspecialchars(@$data['name']['value'])) ?>" />
</div>



In form_input.php process the form and output any error messages and previously entered data to a $data array. Save this in a session variable and redirect back to the form page.


Retrieve the $data array from the session variable and redisplay the form.