Results 1 to 7 of 7

Thread: Swapping echo between pages

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    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

  4. #4

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

  5. #5

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    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.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Swapping echo between pages

    Quote Originally Posted by kows View Post
    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:

    1. 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>
    2. 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.

    3. Retrieve the $data array from the session variable and redisplay the form.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width