Calling External File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SamMan

    Calling External File

    I am fairly new to PHP programming, and I'm trying to get my head around
    this one...

    I have a form that I am doing validation on via PHP within the same page, so
    if there is an error, a message will show to the user above the form. If all
    goes well, I would like to call a processing script that I have already set
    up and working to format the users response and send it out to a specified
    e-mail... I'll call it processing.php

    Is there a way that I can, if the form is filled out correctly, make a call
    to processing.php, that will totally leave the control of form.php and do
    it's processing?

    I hope I'm making myself clear...
    Thanks.

    --


    SamMan
    Rip it to reply



  • Matthias Esken

    #2
    Re: Calling External File

    SamMan schrieb:
    [color=blue]
    > Is there a way that I can, if the form is filled out correctly, make a call
    > to processing.php, that will totally leave the control of form.php and do
    > it's processing?[/color]

    header('Locatio n: http://www.example.com/processing.php' );
    exit;
    [color=blue]
    > I hope I'm making myself clear...[/color]

    I'm not sure ... ;-)


    Regards,
    Matthias

    Comment

    • SamMan

      #3
      Re: Calling External File

      "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
      message news:cdunj8.1lo .1@usenet.esken .de...[color=blue]
      > SamMan schrieb:
      >[color=green]
      > > Is there a way that I can, if the form is filled out correctly, make a[/color][/color]
      call[color=blue][color=green]
      > > to processing.php, that will totally leave the control of form.php and[/color][/color]
      do[color=blue][color=green]
      > > it's processing?[/color]
      >
      > header('Locatio n: http://www.example.com/processing.php' );
      > exit;
      >[color=green]
      > > I hope I'm making myself clear...[/color]
      >
      > I'm not sure ... ;-)
      >
      >
      > Regards,
      > Matthias[/color]


      The problem is that if I use the header method from within the first page
      (form.php) I get an error that the headers have already been sent, or
      something to that effect.... At least this is what I recall was happening
      yesterday. I will give it a try again, and let you know.

      Thanks.

      --


      SamMan
      Rip it to reply


      Comment

      • Michael Austin

        #4
        Re: Calling External File

        SamMan wrote:
        [color=blue]
        > I am fairly new to PHP programming, and I'm trying to get my head around
        > this one...
        >
        > I have a form that I am doing validation on via PHP within the same page, so
        > if there is an error, a message will show to the user above the form. If all
        > goes well, I would like to call a processing script that I have already set
        > up and working to format the users response and send it out to a specified
        > e-mail... I'll call it processing.php
        >
        > Is there a way that I can, if the form is filled out correctly, make a call
        > to processing.php, that will totally leave the control of form.php and do
        > it's processing?
        >
        > I hope I'm making myself clear...
        > Thanks.
        >[/color]

        basically use hidden flag fields to tell you when everything is okay

        if (isset($flag))
        {
        form method=post) // using no method says to use this file
        <input type=hidden name=flag value=1>
        fill in the form and if it is incorrect have them make corrections
        if no corrections needed, then add a hidden field called okay
        form with all correct variables action=processi ng.php
        } else
        {
        form method=post) // using no method says to use this file
        <input type=hidden name=flag value=1>
        other input fields
        submit[color=blue]
        >[/color]

        --
        Michael Austin.
        Consultant - Available.
        Donations welcomed. Http://www.firstdbasource.com/donations.html
        :)

        Comment

        • SamMan

          #5
          Re: Calling External File

          "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
          message news:cdunj8.1lo .1@usenet.esken .de...[color=blue]
          > SamMan schrieb:
          >[color=green]
          > > Is there a way that I can, if the form is filled out correctly, make a[/color][/color]
          call[color=blue][color=green]
          > > to processing.php, that will totally leave the control of form.php and[/color][/color]
          do[color=blue][color=green]
          > > it's processing?[/color]
          >
          > header('Locatio n: http://www.example.com/processing.php' );
          > exit;
          >[color=green]
          > > I hope I'm making myself clear...[/color]
          >
          > I'm not sure ... ;-)
          >
          >
          > Regards,
          > Matthias[/color]


          The error that I'm getting is "Cannot modify header information - headers
          already sent...". Unless I put it at the very top of the page, then it
          works. This will be another challenge, as I will need to put the validation
          code at the top of the page (I'm assuming) and I would like any errors to be
          displayed in a specific location in the form.

          Back to work!
          Thanks.

          --


          SamMan
          Rip it to reply


          Comment

          • SamMan

            #6
            Re: Calling External File

            "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
            message news:cdunj8.1lo .1@usenet.esken .de...[color=blue]
            > SamMan schrieb:
            >[color=green]
            > > Is there a way that I can, if the form is filled out correctly, make a[/color][/color]
            call[color=blue][color=green]
            > > to processing.php, that will totally leave the control of form.php and[/color][/color]
            do[color=blue][color=green]
            > > it's processing?[/color]
            >
            > header('Locatio n: http://www.example.com/processing.php' );
            > exit;
            >[color=green]
            > > I hope I'm making myself clear...[/color]
            >
            > I'm not sure ... ;-)
            >
            >
            > Regards,
            > Matthias[/color]


            Matthias,

            I think I have this sorted out. Doing a test page...
            All the validation code is at the very top of the document, before anything.
            This code checks for errors and sets a flag. If there is no error ($flag=
            ="false"), the processing script is called (using the header() function). In
            the location that I want the error's to display, the flag is checked, and if
            true, the errors displayed. Of course, this is a very simple test of the
            logic.

            I believe I will be able to easily transfer this logic to the form at work.

            Thanks for stimulating my brain!


            --


            SamMan
            Rip it to reply


            Comment

            • Matthias Esken

              #7
              Re: Calling External File

              SamMan wrote:
              [color=blue]
              > I think I have this sorted out. Doing a test page...
              > All the validation code is at the very top of the document, before anything.
              > This code checks for errors and sets a flag. If there is no error ($flag=
              > ="false"), the processing script is called (using the header() function).[/color]

              That's the way I write my scripts. :-)

              Regards,
              Matthias

              Comment

              • SamMan

                #8
                Re: Calling External File

                "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
                message news:ce0e9g.go. 1@usenet.esken. de...[color=blue]
                > SamMan wrote:
                >[color=green]
                > > I think I have this sorted out. Doing a test page...
                > > All the validation code is at the very top of the document, before[/color][/color]
                anything.[color=blue][color=green]
                > > This code checks for errors and sets a flag. If there is no error[/color][/color]
                ($flag=[color=blue][color=green]
                > > ="false"), the processing script is called (using the header()[/color][/color]
                function).[color=blue]
                >
                > That's the way I write my scripts. :-)
                >
                > Regards,
                > Matthias[/color]


                I ended up doing it a little different....
                Everything is still at the top of the doc, and a flag is set on error, but
                if none, the processing (formatting of the e-mail message) is done right
                there. If the message is sent successfully, then a header function is used
                to redirect to a thank you page, if not, an error page.

                I even took it a step further. I have made as much of the scripting into
                includes as I could. I tried to separate the error checking & processing
                into two separate includes, but it didn't like that, so I just made one
                include. Any error message that is to be displayed is handled by an include
                also. This makes for a much cleaner looking page, and helps separate the
                view from the model.

                Thanks again!

                --


                SamMan
                Rip it to reply


                Comment

                Working...