Page 1 of 1
Passing Variables Without Form
Posted: Tue Feb 01, 2011 8:31 am
by leewad
Hi,
I am wanting to pass some variables to another site using post not get so the normal way like
http://www.mywebsite.com/page.php?data1 ... ta2=$data2 does not work as the site has not recognised the submit.
Any ideas on how i can pass these with out using a form?
Thanks
Re: Passing Variables Without Form
Posted: Tue Feb 01, 2011 10:13 am
by AbraCadaver
It will not redirect the browser but try http_post_fields() or http_post_data(). If you need a redirect with the post then you must use javascript:
Code: Select all
function http_post_redirect($url='', $data=array(), $doc=false) {
$data = json_encode($data);
if($doc) {
echo " <html><head></head><body>";
}
echo "
<script type='text/javascript'>
var data = eval('(' + '$data' + ')');
var jsForm = document.createElement('form');
jsForm.method = 'post';
jsForm.action = '$url';
for (var name in data) {
var jsInput = document.createElement('hidden');
jsInput.setAttribute('name', name);
jsInput.setAttribute('value', data[name]);
jsForm.appendChild(jsInput);
}
document.body.appendChild(jsForm);
jsForm.submit();
</script>";
if($doc) {
echo "</body></html>";
}
exit;
}
http_post_redirect('test.php', array('test'=>123));
Re: Passing Variables Without Form
Posted: Tue Feb 01, 2011 12:59 pm
by leewad
Thanks for your post but it does not work so will keep looking
Re: Passing Variables Without Form
Posted: Tue Feb 01, 2011 1:09 pm
by AbraCadaver
leewad wrote:Thanks for your post but it does not work so will keep looking
Works great depending on what you want to do and if you use it properly. You probably want to set the third parameter to
true.
Re: Passing Variables Without Form
Posted: Wed Feb 02, 2011 2:31 am
by leewad
This is the code which i have tried, not sure where i am going wrong?
Code: Select all
<?
function http_post_redirect($url='', $data=array(), $doc=false) {
$data = json_encode($data);
if($doc) {
echo " <html><head></head><body>";
}
echo "
<script type='text/javascript'>
var data = eval('(' + '$data' + ')');
var jsForm = document.createElement('form');
jsForm.method = 'post';
jsForm.action = '$url';
for (var name in data) {
var jsInput = document.createElement('hidden');
jsInput.setAttribute('name', name);
jsInput.setAttribute('value', data[name]);
jsForm.appendChild(jsInput);
}
document.body.appendChild(jsForm);
jsForm.submit();
</script>";
if($doc) {
echo "</body></html>";
}
exit;
}
http_post_redirect('https://forms.netsuite.com/app/site/crm/externalleadpage.nl', array(
'compid' =>'970836',
'formid' => '22',
'h' => 'f43e7e0c1e0469055f30',
'partner' => 'CURRENCYTODAY',
'redirect_count' => '1',
'did_javascript_redirect' => 'T',
'firstname' => 'John',
'lastname' => 'Bateman',
'email' => 'johnbateman99@yahoo.co.uk',
'phone' => '01923887565',
'custentity_your_enquiry' => 'Rates Please',
'submitted' => 'true')
);
?>
Re: Passing Variables Without Form
Posted: Wed Feb 02, 2011 1:08 pm
by AbraCadaver
AbraCadaver wrote:leewad wrote:Thanks for your post but it does not work so will keep looking
Works great depending on what you want to do and if you use it properly. You probably want to set the third parameter to
true.
third parameter true.