...

View Full Version : One form to multiple PHP ?



fractal5
11-22-2011, 02:03 AM
Is there a way where I can have one form submit to multiple phps depending on which button is clicked?

For example if I have:


<FORM action="http://localhost/smatrix/phptest/phpcode1.php" name=optionsform METHOD="POST">
<input type="checkbox" name="criteria[]" value="box1">
<input type="checkbox" name="criteria[]" value="box2">

<INPUT TYPE=SUBMIT VALUE="php1" >
<INPUT TYPE=SUBMIT VALUE="php2" >
</form>

Now the other php would be "http://localhost/smatrix/phptest/phpcode2.php" and that is accessed if button "php2" is clicked. Is there any way to do this without using 2 seperate forms? If statements?

Adee
11-22-2011, 02:14 AM
Is there a way where I can have one form submit to multiple phps depending on which button is clicked?

For example if I have:


<FORM action="http://localhost/smatrix/phptest/phpcode1.php" name=optionsform METHOD="POST">
<input type="checkbox" name="criteria[]" value="box1">
<input type="checkbox" name="criteria[]" value="box2">

<INPUT TYPE=SUBMIT VALUE="php1" >
<INPUT TYPE=SUBMIT VALUE="php2" >
</form>

Now the other php would be "http://localhost/smatrix/phptest/phpcode2.php" and that is accessed if button "php2" is clicked. Is there any way to do this without using 2 seperate forms? If statements?

just rename your script to phpcode.php then change the value of each textbox to php1 and php2 then in phpcode.php use a switch or something

tangoforce
11-22-2011, 02:15 AM
Well thats a clientside / javascript question so it doesn't belong here.

The short answer is NO. You can't do this in php on the client side in the web page.

Yes, it can be done via the clientside in javascript so ask in that forum.


just rename your script to phpcode.php then change the value of each textbox to php1 and php2 then in phpcode.php use a switch or something

HE's asking if it can be done on the client side not in php via curl. He's asking if its possible to have multiple actions in the form.

XterM
11-22-2011, 02:56 AM
i try to answer it well. i have 2 method to resolv this issue. first, using javascript to manipulate "action" form. 2nd, using httprequest inside server side.

#1st


<FORM action="http://localhost/smatrix/phptest/phpcode1.php" name=optionsform METHOD="POST">
<input type="checkbox" name="criteria[]" value="box1">
<input type="checkbox" name="criteria[]" value="box2">

<INPUT TYPE=button VALUE="php1" onclick="this.form.action='http://localhost/smatrix/phptest/phpcode1.php';this.form.submit()">
<INPUT TYPE=button VALUE="php2" onclick="this.form.action='http://localhost/smatrix/phptest/phpcode2.php';this.form.submit()">
</form>


it is just simple way. just manipulate "action" url on button click. then submit the form. you can look at "submit" button, it's type not submit, but button.

#2nd: Switch action on server side

a. input form.


<FORM action="http://localhost/smatrix/phptest/phpcode.php" name=optionsform METHOD="POST">
<input type="checkbox" name="criteria[]" value="box1">
<input type="checkbox" name="criteria[]" value="box2">

<INPUT TYPE=submit name=postTo VALUE="php1">
<INPUT TYPE=submit name=postTo VALUE="php2">
</form>


form action just to phpcode.php
look at submit button. 2 submit button with same name, but different value. it used to switch action page.

b. phpcode.php
here, doing switch to post action.


<?php

$postTo = $_POST[postTo];

//here is we define the action page by $postTo :)
switch($postTo){
case "PHP1" : $action = "action_1.php"; break;
case "PHP2" : $action = "action_2.php"; break;
}


//then, post it using httprequest inside of server side.
//I am put a class named httpquery in this script. look at bottom.
//actually, I using a small script called "HTTPQuery". it written by xcrew's team. it is very help full.
//source: http://explorecrew.org/portal.php?page=read&ID=242#Class HTTPQuery

//ok, do it post

//define httpquery's environ
$http = new HTTPRequest; //create an object of httpquery
$http->URL = $action; //POST ACTION PAGE
$http->POST = true; //enable post method


//ok. now, collect datas want to posted
foreach($_POST as $name => $value){
$data .= $name."=".$value."&";
}
$http->Data = $data; //define post datas

//well, just do the query
$http->Query(); //do queries


//query was done. now, get the server output
if($http->Response){
echo $http->Response;
}

//done


//class httpquery
#By ArRay Dec 2nd, 2010
class HTTPRequest {
public $URL;
public $POST = false;
public $GET = true;
public $Data;
public $Port = 80;
public $Response;
public $Referer = "www.ExploreCrew.org";
public $Accept = "*/*";
public $UserAgent = "NetExplorer/5.0";
public $Connection = "Close";

function Query(){
$url = str_replace("http://","",$this->URL);
$host = explode("/",$url);
for($i=1;$i<count($host);$i++){
$path .= "/".$host[$i];
}
if(!$this->POST) $path .= "?".$this->Data;
$sock = @fsockopen($host[0],$this->Port,$errno,$errstr,30);
if ($sock) {
$request = (($this->POST)?"POST":"GET")." ".$path." HTTP/1.1\r\n";
$request .= "Host: ".$host[0]."\r\n";
$request .= "Referer: ".$this->Referer."\r\n";
$request .= "Accept: ".$this->Accept."\r\n";
$request .= "User-Agent: ".$this->UserAgent."\r\n";
$request .= ($this->POST)?"Content-type: application/x-www-form-urlencoded\r\n":"";
$request .= ($this->POST)?"Content-length: ".strlen($this->Data)."\r\n":"";
$request .= "Connection: ".$this->Connection."\r\n\r\n";
@fputs($sock,$request);
if($this->POST)@fputs($sock,$this->Data);
while (!@feof($sock)) {
$output .= @trim(@fgets($sock, 3600))."\n";
}
@fclose($sock);
}
else {
$output = "Can not connect to ".$host[0]." on port ".$this->Port;
}
$this->Response = $output;
}
}

?>

all input from form, will posted, look at "collect data" secsion.

I am sorry, my english is very bad. Hope it help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum