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
Passing Variables Without Form
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Passing Variables Without Form
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));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Passing Variables Without Form
Thanks for your post but it does not work so will keep looking
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Passing Variables Without Form
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.leewad wrote:Thanks for your post but it does not work so will keep looking
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Passing Variables Without Form
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')
);
?>- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Passing Variables Without Form
third parameter true.AbraCadaver wrote: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.leewad wrote:Thanks for your post but it does not work so will keep looking
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.