|
-
Feb 3rd, 2010, 12:39 AM
#1
Thread Starter
Fanatic Member
Swapping echo between pages
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)
Code:
<form method="post" action="checklogin.php" name="loginform">
-
Feb 3rd, 2010, 12:59 AM
#2
Re: Swapping echo between pages
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.
-
Feb 3rd, 2010, 01:43 AM
#3
Thread Starter
Fanatic Member
Re: Swapping echo between pages
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
-
Feb 3rd, 2010, 06:01 AM
#4
Banned
Re: Swapping echo between pages
I think this code will work for transferring data from one page to another.
Code:
<form method="post" action="checklogin.php" name="loginform">
-
Feb 3rd, 2010, 06:51 AM
#5
Thread Starter
Fanatic Member
Re: Swapping echo between pages
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.
-
Feb 3rd, 2010, 12:01 PM
#6
Re: Swapping echo between pages
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.
-
Feb 4th, 2010, 07:50 AM
#7
Re: Swapping echo between pages
 Originally Posted by kows
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.:
PHP Code:
<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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|