Submit a form & go to the new page after validate

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

    #1

    Submit a form & go to the new page after validate

    Hi,

    A difficult question.

    I have a form that I used to submit to https://www. paypal.com/cgi-bin/
    webscr
    <form action="https://www. paypal.com/cgi-bin/webscr" method="post">

    Now I need to validate some inputs of this form, so I submit it to a
    PHP page in my own server first.
    <form action="paypal_ upgrade_checkin g.php" method="post">

    After validate, I need to submit the form again to https://www.
    paypal.com/cgi-bin/webscr
    I write a piece of PHP code but it failed. The browse is still in
    paypal_upgrade_ checking.php, it doesn't go to the new page.
    I wonder whether there is a way to do it.


    <?
    ....
    $buf = '';

    $req = '';

    foreach ($_POST as $key =$value) {
    $value = urlencode(strip slashes($value) );
    $req .= "&$key=$val ue";
    }

    $header="";
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);


    if (!$fp) {
    // HTTP ERROR
    print "HTTP ERROR<br/>$errno<br/>$errstr";
    exit();
    } else {
    fputs ($fp, $header . $req);
    while(!feof($fp )) {
    $buf.=fgets($fp ,1024);
    }
    fclose($fp);
    echo $buf;
    }
    ?>

    Thank you
    Kelvin

  • Jerry Stuckle

    #2
    Re: Submit a form &amp; go to the new page after validate

    kelvin wrote:
    Hi,
    >
    A difficult question.
    >
    I have a form that I used to submit to https://www. paypal.com/cgi-bin/
    webscr
    <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
    >
    Now I need to validate some inputs of this form, so I submit it to a
    PHP page in my own server first.
    <form action="paypal_ upgrade_checkin g.php" method="post">
    >
    After validate, I need to submit the form again to https://www.
    paypal.com/cgi-bin/webscr
    I write a piece of PHP code but it failed. The browse is still in
    paypal_upgrade_ checking.php, it doesn't go to the new page.
    I wonder whether there is a way to do it.
    >
    >
    <?
    ...
    $buf = '';
    >
    $req = '';
    >
    foreach ($_POST as $key =$value) {
    $value = urlencode(strip slashes($value) );
    $req .= "&$key=$val ue";
    }
    >
    $header="";
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
    >
    >
    if (!$fp) {
    // HTTP ERROR
    print "HTTP ERROR<br/>$errno<br/>$errstr";
    exit();
    } else {
    fputs ($fp, $header . $req);
    while(!feof($fp )) {
    $buf.=fgets($fp ,1024);
    }
    fclose($fp);
    echo $buf;
    }
    ?>
    >
    Thank you
    Kelvin
    >
    Kelvin,

    Do it the easy way - use CURL to do your posting.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • kelvin

      #3
      Re: Submit a form &amp; go to the new page after validate

      Thank you, but there is no curl on my web hosting server.
      Is it possible to use something like javascript together if it is too
      difficult to use PHP only?


      Thank you,
      Kelvin

      Comment

      • ED

        #4
        Re: Submit a form &amp; go to the new page after validate


        "kelvin" <kelvin_gl@yaho o.com.cnwrote in message
        news:1184294668 .080879.180150@ m37g2000prh.goo glegroups.com.. .
        Hi,
        >
        A difficult question.
        >
        I have a form that I used to submit to https://www. paypal.com/cgi-bin/
        webscr
        <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
        >
        Now I need to validate some inputs of this form, so I submit it to a
        PHP page in my own server first.
        <form action="paypal_ upgrade_checkin g.php" method="post">
        >
        After validate, I need to submit the form again to https://www.
        paypal.com/cgi-bin/webscr
        I write a piece of PHP code but it failed. The browse is still in
        paypal_upgrade_ checking.php, it doesn't go to the new page.
        I wonder whether there is a way to do it.
        >
        >
        <?
        ...
        $buf = '';
        >
        $req = '';
        >
        foreach ($_POST as $key =$value) {
        $value = urlencode(strip slashes($value) );
        $req .= "&$key=$val ue";
        }
        >
        $header="";
        $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
        $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
        $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
        >
        >
        if (!$fp) {
        // HTTP ERROR
        print "HTTP ERROR<br/>$errno<br/>$errstr";
        exit();
        } else {
        fputs ($fp, $header . $req);
        while(!feof($fp )) {
        $buf.=fgets($fp ,1024);
        }
        fclose($fp);
        echo $buf;
        }
        ?>
        >
        Thank you
        Kelvin
        >
        Hi Kelvin,
        Presuming that you want to redirect the browser a quick easy fix may be to
        use GET instead of POST to submit to paypal (IIRC they support both
        methods):
        ie, using $req from your existing code:

        $url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
        header("Locatio n: $url");
        exit;

        cheers,
        ED




        Comment

        • Captain Paralytic

          #5
          Re: Submit a form &amp; go to the new page after validate

          On 13 Jul, 03:44, kelvin <kelvin...@yaho o.com.cnwrote:
          Hi,
          >
          A difficult question.
          >
          I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
          webscr
          <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
          >
          Now I need to validate some inputs of this form, so I submit it to a
          PHP page in my own server first.
          <form action="paypal_ upgrade_checkin g.php" method="post">
          >
          After validate, I need to submit the form again tohttps://www.
          paypal.com/cgi-bin/webscr
          I write a piece of PHP code but it failed. The browse is still in
          paypal_upgrade_ checking.php, it doesn't go to the new page.
          I wonder whether there is a way to do it.
          >
          <?
          ...
          $buf = '';
          >
          $req = '';
          >
          foreach ($_POST as $key =$value) {
          $value = urlencode(strip slashes($value) );
          $req .= "&$key=$val ue";
          }
          >
          $header="";
          $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
          $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
          $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
          $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
          >
          if (!$fp) {
          // HTTP ERROR
          print "HTTP ERROR<br/>$errno<br/>$errstr";
          exit();
          } else {
          fputs ($fp, $header . $req);
          while(!feof($fp )) {
          $buf.=fgets($fp ,1024);
          }
          fclose($fp);
          echo $buf;
          }
          ?>
          >
          Thank you
          Kelvin
          This code will cause the sver to communicate with paypal, it won't
          affect the browser.

          You could send the form to the clinet and send an onload() script to
          automatically submit it.

          Comment

          • Jerry Stuckle

            #6
            Re: Submit a form &amp; go to the new page after validate

            kelvin wrote:
            Thank you, but there is no curl on my web hosting server.
            Is it possible to use something like javascript together if it is too
            difficult to use PHP only?
            >
            >
            Thank you,
            Kelvin
            >
            Don't know. Try a javascript newsgroup.

            Or, if your hosting company won't install CURL, get another host.
            They're are enough good ones around, and there's no reason to fight what
            can be easily fixed.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Jerry Stuckle

              #7
              Re: Submit a form &amp; go to the new page after validate

              Captain Paralytic wrote:
              On 13 Jul, 03:44, kelvin <kelvin...@yaho o.com.cnwrote:
              >Hi,
              >>
              >A difficult question.
              >>
              >I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
              >webscr
              ><form action="https://www. paypal.com/cgi-bin/webscr" method="post">
              >>
              >Now I need to validate some inputs of this form, so I submit it to a
              >PHP page in my own server first.
              ><form action="paypal_ upgrade_checkin g.php" method="post">
              >>
              >After validate, I need to submit the form again tohttps://www.
              >paypal.com/cgi-bin/webscr
              >I write a piece of PHP code but it failed. The browse is still in
              >paypal_upgrade _checking.php, it doesn't go to the new page.
              >I wonder whether there is a way to do it.
              >>
              ><?
              >...
              > $buf = '';
              >>
              > $req = '';
              >>
              > foreach ($_POST as $key =$value) {
              > $value = urlencode(strip slashes($value) );
              > $req .= "&$key=$val ue";
              > }
              >>
              > $header="";
              > $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
              > $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
              > $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
              > $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
              >>
              > if (!$fp) {
              > // HTTP ERROR
              > print "HTTP ERROR<br/>$errno<br/>$errstr";
              > exit();
              > } else {
              > fputs ($fp, $header . $req);
              > while(!feof($fp )) {
              > $buf.=fgets($fp ,1024);
              > }
              > fclose($fp);
              > echo $buf;
              > }
              >?>
              >>
              >Thank you
              >Kelvin
              >
              This code will cause the sver to communicate with paypal, it won't
              affect the browser.
              >
              You could send the form to the clinet and send an onload() script to
              automatically submit it.
              >
              The problem with that is he won't know if the transaction succeeded or not.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Captain Paralytic

                #8
                Re: Submit a form &amp; go to the new page after validate

                On 13 Jul, 12:57, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                Captain Paralytic wrote:
                On 13 Jul, 03:44, kelvin <kelvin...@yaho o.com.cnwrote:
                Hi,
                >
                A difficult question.
                >
                I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
                webscr
                <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
                >
                Now I need to validate some inputs of this form, so I submit it to a
                PHP page in my own server first.
                <form action="paypal_ upgrade_checkin g.php" method="post">
                >
                After validate, I need to submit the form again tohttps://www.
                paypal.com/cgi-bin/webscr
                I write a piece of PHP code but it failed. The browse is still in
                paypal_upgrade_ checking.php, it doesn't go to the new page.
                I wonder whether there is a way to do it.
                >
                <?
                ...
                $buf = '';
                >
                $req = '';
                >
                foreach ($_POST as $key =$value) {
                $value = urlencode(strip slashes($value) );
                $req .= "&$key=$val ue";
                }
                >
                $header="";
                $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
                $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
                $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
                $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
                >
                if (!$fp) {
                // HTTP ERROR
                print "HTTP ERROR<br/>$errno<br/>$errstr";
                exit();
                } else {
                fputs ($fp, $header . $req);
                while(!feof($fp )) {
                $buf.=fgets($fp ,1024);
                }
                fclose($fp);
                echo $buf;
                }
                ?>
                >
                Thank you
                Kelvin
                >
                This code will cause the sver to communicate with paypal, it won't
                affect the browser.
                >
                You could send the form to the clinet and send an onload() script to
                automatically submit it.
                >
                The problem with that is he won't know if the transaction succeeded or not.
                >
                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstuck...@attgl obal.net
                =============== ===- Hide quoted text -
                >
                - Show quoted text -
                But my reading of what he said is the he wants to validate data in the
                form before posting it and redirecting the user to the paypal site.
                Indeed he specifically says that the user stays on his page, rather
                than being sent to the paypal page.

                So the validation is to be done BEFORE sending the form (and the user)
                to the paypal site.

                I would tend to do the validation by javascript if possible, or if I
                had to do it serverside I'd use AJAX methods.


                Comment

                • Jerry Stuckle

                  #9
                  Re: Submit a form &amp; go to the new page after validate

                  Captain Paralytic wrote:
                  >
                  But my reading of what he said is the he wants to validate data in the
                  form before posting it and redirecting the user to the paypal site.
                  Indeed he specifically says that the user stays on his page, rather
                  than being sent to the paypal page.
                  >
                  So the validation is to be done BEFORE sending the form (and the user)
                  to the paypal site.
                  >
                  I would tend to do the validation by javascript if possible, or if I
                  had to do it serverside I'd use AJAX methods.
                  >
                  >
                  Either of which fail if JS is disabled, for instance.

                  I've got one site I took over from another webmaster which does this.
                  It's written in VBScript/ASP, so CURL isn't an option. The problem is
                  it requires additional work for the admin people to process the request
                  once payment has been completed. And this time can really add up.

                  Another PHP site I have which uses CURL is fully automated. No
                  additional work to process the payment required at all.


                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • kelvin

                    #10
                    Re: Submit a form &amp; go to the new page after validate

                    On Jul 13, 4:10 am, "ED" <e...@example.c omwrote:
                    "kelvin" <kelvin...@yaho o.com.cnwrote in message
                    >
                    news:1184294668 .080879.180150@ m37g2000prh.goo glegroups.com.. .
                    >
                    >
                    >
                    Hi,
                    >
                    A difficult question.
                    >
                    I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
                    webscr
                    <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
                    >
                    Now I need to validate some inputs of this form, so I submit it to a
                    PHP page in my own server first.
                    <form action="paypal_ upgrade_checkin g.php" method="post">
                    >
                    After validate, I need to submit the form again tohttps://www.
                    paypal.com/cgi-bin/webscr
                    I write a piece of PHP code but it failed. The browse is still in
                    paypal_upgrade_ checking.php, it doesn't go to the new page.
                    I wonder whether there is a way to do it.
                    >
                    <?
                    ...
                    $buf = '';
                    >
                    $req = '';
                    >
                    foreach ($_POST as $key =$value) {
                    $value = urlencode(strip slashes($value) );
                    $req .= "&$key=$val ue";
                    }
                    >
                    $header="";
                    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
                    $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
                    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
                    $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
                    >
                    if (!$fp) {
                    // HTTP ERROR
                    print "HTTP ERROR<br/>$errno<br/>$errstr";
                    exit();
                    } else {
                    fputs ($fp, $header . $req);
                    while(!feof($fp )) {
                    $buf.=fgets($fp ,1024);
                    }
                    fclose($fp);
                    echo $buf;
                    }
                    ?>
                    >
                    Thank you
                    Kelvin
                    >
                    Hi Kelvin,
                    Presuming that you want to redirect the browser a quick easy fix may be to
                    use GET instead of POST to submit to paypal (IIRC they support both
                    methods):
                    ie, using $req from your existing code:
                    >
                    $url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
                    header("Locatio n: $url");
                    exit;
                    >
                    cheers,
                    ED
                    It works for me.

                    Thank you a lot,
                    Kelvin

                    Comment

                    • kelvin

                      #11
                      Re: Submit a form &amp; go to the new page after validate

                      On Jul 13, 4:10 am, "ED" <e...@example.c omwrote:
                      "kelvin" <kelvin...@yaho o.com.cnwrote in message
                      >
                      news:1184294668 .080879.180150@ m37g2000prh.goo glegroups.com.. .
                      >
                      >
                      >
                      Hi,
                      >
                      A difficult question.
                      >
                      I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
                      webscr
                      <form action="https://www. paypal.com/cgi-bin/webscr" method="post">
                      >
                      Now I need to validate some inputs of this form, so I submit it to a
                      PHP page in my own server first.
                      <form action="paypal_ upgrade_checkin g.php" method="post">
                      >
                      After validate, I need to submit the form again tohttps://www.
                      paypal.com/cgi-bin/webscr
                      I write a piece of PHP code but it failed. The browse is still in
                      paypal_upgrade_ checking.php, it doesn't go to the new page.
                      I wonder whether there is a way to do it.
                      >
                      <?
                      ...
                      $buf = '';
                      >
                      $req = '';
                      >
                      foreach ($_POST as $key =$value) {
                      $value = urlencode(strip slashes($value) );
                      $req .= "&$key=$val ue";
                      }
                      >
                      $header="";
                      $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
                      $header .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
                      $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
                      $fp = fsockopen ('www.sandbox.p aypal.com', 80, $errno, $errstr, 30);
                      >
                      if (!$fp) {
                      // HTTP ERROR
                      print "HTTP ERROR<br/>$errno<br/>$errstr";
                      exit();
                      } else {
                      fputs ($fp, $header . $req);
                      while(!feof($fp )) {
                      $buf.=fgets($fp ,1024);
                      }
                      fclose($fp);
                      echo $buf;
                      }
                      ?>
                      >
                      Thank you
                      Kelvin
                      >
                      Hi Kelvin,
                      Presuming that you want to redirect the browser a quick easy fix may be to
                      use GET instead of POST to submit to paypal (IIRC they support both
                      methods):
                      ie, using $req from your existing code:
                      >
                      $url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
                      header("Locatio n: $url");
                      exit;
                      >
                      cheers,
                      ED
                      It works for me too.

                      Thank you a lot,
                      Kelvin

                      Comment

                      Working...