Submit/Post with variables that aren't in a form
Moderator: General Moderators
Submit/Post with variables that aren't in a form
I need to click a button which will trigger a calculation and then post the result of the calculation to a new form. However, the calculation won't be in a control. Everything I read about PHP shows that a submit button can only post data that is in a form. Is there any way to do this with a variable, not a control's value?
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: Submit/Post with variables that aren't in a form
There are two possibilities - (1)Put the variable in a hidden input field (see below) inside form or (2) use Ajax - use javascript to post the variable.
Code: Select all
<form action=action.php><input type=hidden name='variable_name' value='<?php echo $variable ?>' /> <input type=submit></form>Re: Submit/Post with variables that aren't in a form
You could just stick it in the URL using a document.location redirect.
Code: Select all
document.location.href = "foo.php?bar=" + calculate();-
maneetpuri
- Forum Commoner
- Posts: 60
- Joined: Tue Oct 07, 2008 6:32 am
Re: Submit/Post with variables that aren't in a form
Hi,
Submit the first form and pass the control to a PHP script on this script do the calculation you want to do and on this script create a form and in the required form field set the value to the result of the calculation.
Hope this helps.
Cheers,
~Maneet
Submit the first form and pass the control to a PHP script on this script do the calculation you want to do and on this script create a form and in the required form field set the value to the result of the calculation.
Hope this helps.
Cheers,
~Maneet
- phdatabase
- Forum Commoner
- Posts: 83
- Joined: Fri May 28, 2010 10:02 am
- Location: Fort Myers, FL
Re: Submit/Post with variables that aren't in a form
This is an excellent reason to investigate CURL. CURL makes working with HTTP easy.
CURLOPT_POSTFIELDS The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. This can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.
find it here: http://us.php.net/manual/en/function.curl-setopt.php
CURLOPT_POSTFIELDS The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. This can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.
find it here: http://us.php.net/manual/en/function.curl-setopt.php