Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    One form to multiple PHP ?

    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:

    Code:
    <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?

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    Quote Originally Posted by fractal5 View Post
    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:

    Code:
    <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

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,323
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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.

    Quote Originally Posted by Adee View Post
    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.
    Last edited by ShaneC; 11-22-2011 at 01:42 AM. Reason: Merged double post
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    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
    Code:
    <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.
    Code:
    <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.
    Code:
    <?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?pa...d&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.
    Last edited by XterM; 11-22-2011 at 01:58 AM.


  •  

    Posting Permissions

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