Forum Moderators: coopster
Just a bit of background - the reason why I'd like to do this is because I have multiple contact us forms on a site, and for efficiency purposes, I'd like to have a single form mail script so that I don't have to keep editing the php.
B. When the validation is dynamically writing out a complete form of hidden variables and then posting them with javascript.
Neither are particularly elegant in my opinion.
Maybe use fputs?
Ally
file1.php
-------------
// validate here
....
// post to another file via GET
file_get_contents("http://www.yoursite.com/file2.php?param1=aaa¶m2=bbb");
If you would like to post to another file via POST then you'll need to do that via socket, or using cURL.
using the above situation of file1.php and file2.php
file1.php
---------------
//validate here
---------------
now in file1.php you could store all the values you want to keep in hidden form attributes for example if you want to keep $id
<input type="hidden" name="id" value="<?php echo $id;?>" />
i assume that the form contains some kind of submit button once pressed it leads to file2.php
in file2.php put
$id = $_POST['id'];
this will transfer the value from file1.php to file2.php, its similar to $_GET but you dont pass the parameters using the URL, alternativel you could use sessions, just a quick example on sessions
file1.php
------------------
session_start();
//if $id is valid
$_SESSION['id'] = $id;
//else error
------------------
then
file2.php
----------------
session_start();
if(isset($_SESSION['id']) {
echo $_SESSION['id'];
} else {
echo "error";
}
PS - Sorry its all a bit messy and not very clear, Its 3am here and im tired, if you want more detailed examples just say, anyway, im off to bed, oh and sorry for my terrible spelling, again i blame the lack of sleep i have had.
PS - PS - the only valid php is the very last instance of file2.php, this will work if you copy and paste it, the rest have been simplified.
Here's how it works:
File 1:
1: startsession(); 2: $_SESSION['form_contents'] = $form_contents; or
2: $_SESSION['to'] = $to;
3: $_SESSION['from'] = $from; etc.
File 2:
1: startsession(); 2: $form_contents = $_SESSION['form_contents']; or
2: $to = $_SESSION['to'];
3: $from = $_SESSION['from']; etc.
It's also just as secure (or more secure) than using POST.
You can find out more here [us3.php.net].