Bluehost.com Web Hosting $6.95

processing 2 things in one form. is it possible?

This is a discussion on processing 2 things in one form. is it possible? within the PHP Language forums, part of the PHP Programming Forums category; hi all, i am creating a form that returns to itself like this: <form name="form1" action=&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-04-2006
crescent_au@yahoo.com
 
Posts: n/a
Default processing 2 things in one form. is it possible?

hi all,

i am creating a form that returns to itself like this:
<form name="form1" action="<?php echo $_REQUEST['PHP_SELF']; ?>"
method="post">

Upon clicking submit, I want the form to return to "itself" (does the
input fields validation). If the validation is false, the initial input
values are displayed on the fields. If the validation is correct, it
should go to an external file (on different server) and does the rest
of the processing such as sending mail or writing to a file, etc (could
be anything). There are basically 2 tasks here. Is this achievable in a
single form. I tried to include external file after validation but it
fails to call a function inside that file as the file resides on a
different server.

Can someone show me the right direction?

Thanks

Reply With Quote
  #2 (permalink)  
Old 10-04-2006
pittendrigh
 
Posts: n/a
Default Re: processing 2 things in one form. is it possible?


crescent...@yahoo.com wrote:

> Upon clicking submit, I want the form to return to "itself" (does the
> input fields validation). If the validation is false, the initial input
> values are displayed on the fields. If the validation is correct, it
> should go to an external file (on different server) and does the rest
> of the processing such as sending mail or writing to a file, etc (could
> be anything).


if($_SERVER['REQUEST_METHOD'] == 'GET')
{
...show the form
}
elseif post
{
validate the post vars
if success
use the header() function to jump the external page
else
show the form again, you'll still have
the $_POST array hanging around to initialize
the form elements with, so the form looks
like it did just before the first submit
}

Reply With Quote
  #3 (permalink)  
Old 10-04-2006
Johnny
 
Posts: n/a
Default Re: processing 2 things in one form. is it possible?


"pittendrigh" <Sandy.Pittendrigh@gmail.com> wrote in message
news:1159971142.114178.260610@m73g2000cwd.googlegr oups.com...
>
> crescent...@yahoo.com wrote:
>
> > Upon clicking submit, I want the form to return to "itself" (does the
> > input fields validation). If the validation is false, the initial input
> > values are displayed on the fields. If the validation is correct, it
> > should go to an external file (on different server) and does the rest
> > of the processing such as sending mail or writing to a file, etc (could
> > be anything).

>
> if($_SERVER['REQUEST_METHOD'] == 'GET')
> {
> ...show the form
> }
> elseif post
> {
> validate the post vars
> if success
> use the header() function to jump the external page
> else
> show the form again, you'll still have
> the $_POST array hanging around to initialize
> the form elements with, so the form looks
> like it did just before the first submit
> }
>


The only problem I see with that is that the OP probably wants to take data
along to the new script(on different server) and header won't do that by
itself afaik. You may need to use curl to repost your data to the other
server.


Reply With Quote
  #4 (permalink)  
Old 10-05-2006
Nick Ashley
 
Posts: n/a
Default Re: processing 2 things in one form. is it possible?

One solution is to use fsockopen to post the data to the other server.
Create a function which takes as input a URL to post to, and an array
of variables to be posted. This function could then connect the URL,
post the data, and return the response. Note that the response will
contain all data return from the server (including headers). Therefore,
the remote server's page should echo results in an easily parsable
form. I usually do something along the lines of:

<!-- OUTPUT STARTS HERE -->
<result>1</result>

This way you can easily cut off the headers, and look at the actual
result of the operation. Here is a code snippet of using fsockopen:

$request.="POST ".$URL_Info["path"]." HTTP/1.1\r\n";
$request.="Host: ".$URL_Info["host"]."\r\n";
$request.="Referer: $referrer\r\n";
$request.="Content-type: application/x-www-form-urlencoded\r\n";
$request.="Content-length: ".strlen($data_string)."\r\n";
$request.="Connection: close\r\n";
$request.="\r\n";
$request.=$data_string."\r\n";


$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
fputs($fp, $request);
while(!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp);

On Oct 4, 8:38 am, "Johnny" <removethis.huuan...@hotmail.com> wrote:
> "pittendrigh" <Sandy.Pittendr...@gmail.com> wrote in messagenews:1159971142.114178.260610@m73g2000cwd.g ooglegroups.com...
>
>
>
>
>
> > crescent...@yahoo.com wrote:

>
> > > Upon clicking submit, I want the form to return to "itself" (does the
> > > input fields validation). If the validation is false, the initial input
> > > values are displayed on the fields. If the validation is correct, it
> > > should go to an external file (on different server) and does the rest
> > > of the processing such as sending mail or writing to a file, etc (could
> > > be anything).

>
> > if($_SERVER['REQUEST_METHOD'] == 'GET')
> > {
> > ...show the form
> > }
> > elseif post
> > {
> > validate the post vars
> > if success
> > use the header() function to jump the external page
> > else
> > show the form again, you'll still have
> > the $_POST array hanging around to initialize
> > the form elements with, so the form looks
> > like it did just before the first submit
> > }The only problem I see with that is that the OP probably wants to take data

> along to the new script(on different server) and header won't do that by
> itself afaik. You may need to use curl to repost your data to the other
> server.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:25 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0