I have an html form(say data.html) that will POST data to a php file(say, a.php). I wish to have that php page (a.php) to submit the same data to another php (say, b.php) file (using POST function) with out any input from the user. Please suggest some way.
You could try using some javascript; <body onload='document.myform.submit();'> <form name='myform' action='mypage.php' method='POST'> <input type='hidden' name='field1' value='<?=$_POST['field1']?>' /> </form> HTML: Alternatively you could use sessions and store your posted variables in the session and just redirect the user to the 2nd page; <?php session_start(); foreach($_POST as $field => $value){ $_SESSION[$field] = $value; } header('Location: mypage.php'); ?> PHP:
thanks for the help. but have some problem in implement ion Here is the code I used <?php preg_match('/I am from ([a-z]+)/i',$_POST['search_var'],$match); #print_r($_POST); #print_r($match); session_start(); if(isset($_POST['search_var'])) { $_SESSION = $_POST header('Location: '.$match[1].'.php'); exit; ?> I want the user to be redirected to the next page and prints the data he entered. If he had entered the data as "I am from usa. How are you?" He should be redirected to usa.php and that page should display "I am from usa. How are you?"
So you want to have a data form, a user enters data, the data submits and shows the user what data he has entered, then finally he confirms?? If this is the case then you can just pass the variables to the a.php script which will do the relevant database work or woteva. This script can then build then html placing the appropriate variable values in the appropriate places on the page. The user can then click confirm to complete which will run b.php to do final database work and finally display success page. Im not too sure on what you are asking but that is how I would do what I think your asking
Then please do. ___________________________________ Your first HTML file I assume you already have... This goes to the first PHP, I'm not going to include any decent validation here as I assume you can do it yourself... <?php /** * Danltn | http://danltn.com/ * MSN: * Email: * Started: 27/6/2008 15:02 (UK) * Tested: No * PHP 4/5: Both * No warranty is given to code used */ $buffer = ''; // Initialize the variables. $hidden = ''; $_POST = array_map('htmlentities', $_POST); // Very basic validation, stops XSS foreach($_POST as $key => $value) : $hidden .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\n"; $buffer .= ucwords(strtolower($key)) . ': ' . $value . '<br />' . "\n"; endforeach; unset($key, $value); // Remove what we've used, get some more memory ?> <form method="post" action="b.php"> Your input:<br /> <?php echo $buffer , $hidden; ?> Submit: <input type="submit" name="submit" value="It's all correct!" /> </form>
But the automatic redirection will not work in this case. If the user enters the data as "I am from usa. How are you?" He should be redirected to usa.php and that page should display "I am from usa. How are you?" And if he enters "I am from uk. How are you?" He should be redirected to uk.php and that page should simply display "I am from uk. How are you?" A simple redirection the respective page (say usa.php or uk.php) is what I require (along with the POST data). I require your help in this aspect
i found some info in' http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html can any one help me in applying that to my scripts and retain the "header('Location: '.$match[1].'.php');" in the script
Why not just use a hidden form? Once "a.php" passes data to "b.php" through a form using POST, simply receive the value in "b.php" through $_POST['val'] and place them in a hidden form for sending to "c.php" also through POST. This allows you to pass information to an infinite number of pages using POST. Alternatively, instead of having to list down every variable you receive form POST, you can use this instead which mimics the config "register_globals=on" when in reality it's really off: //makes variables of the "name" attribute of your forms and //assigns the "value" attribute to it automatically. Cool yah? foreach ($_POST as $key => $val){ $$key = $val; } PHP: If you have a form with name="address", you can simply access its value as $address without having to go through $address = $_POST['address']; PHP:
enchance: Well if you want vulnerabilities, just use: extract($_POST); (It's the same as that loop, but with more options )