Using a variable for a hidden input value

K

Kim

I'm trying to replace a fixed " value="0" " in <input type="hidden"
name="config" value="0" /> with value=variable.

My variable value is derived as follows:
Select payment method: <select size="1" name="variable">
<option value="1">PayPal</option><option value="0">Check/Money Order
Pre-Pay</option></select>

My PHP script chokes on: <input type="hidden" name="config" value=variable
/> or variable in quotes.

Any suggestions?
 
S

smokeyd

Where is the php choking, when writing the html or when the form is
submitted? If you post up the full code I will try and help..
 
K

Kim

smokeyd said:
Where is the php choking, when writing the html or when the form is
submitted? If you post up the full code I will try and help..
The PHP is choking because I'm not sending it a "0", "1", or "2".

I really just need to understand how to dynamically generate the value for
the "value=" in my
<input type="hidden" name="config" value="0" />

I need someone familiar with the syntax, this same method is used for PayPal
submit.
http://www.paypal.com/cgi-bin/webscr?cmd=_pdn_xclick_prepopulate_outside
 
J

Jonathan N. Little

Kim said:
The PHP is choking because I'm not sending it a "0", "1", or "2".

I really just need to understand how to dynamically generate the value for
the "value=" in my
<input type="hidden" name="config" value="0" />

I need someone familiar with the syntax, this same method is used for PayPal
submit.
http://www.paypal.com/cgi-bin/webscr?cmd=_pdn_xclick_prepopulate_outside

The question is how are you setting the php variable, $phpVariable? From
a previous form submission or are you trying to set the value
dynamically before the form is submitted?

If former, then you either have to have some form input that you capture
in this form or derive the value to set to your variable $phpVariable.
Then you have to insert it into your HTML like:

<input type="hidden" name="config" value="<?php echo $phpVariable; ?>" />


It the latter, then we are talking about client-side JavaScript, a
method that is becoming increasingly unreliable as more folks are
disabling their JavaScript in their browsers

What smokeyed requested was the php code that you are using to set the
form field...
 
A

Adam Pflug

what you actually want is

<input type="hidden" name="config" value="<?php echo
$_REQUEST['variable']; ?>" />

or at least I think. If you could give us a little more info we could
help you better
 
Joined
Aug 4, 2009
Messages
1
Reaction score
0
Same problem and here are the full details...

I'm running into the same problem and I know it's a matter of syntax so any help would be spectacular.
I'm passing a username variable from Joomla to log into a related site.
I've tried 2 different solutions and neither seems to work
The code that's giving me trouble is as follows:

Solution 1 (cURL seems to do absolutely nothing useful as it gives me connection results ad times and so forth but never actually redirects the page):

<?php
defined('_JEXEC') OR defined('_VALID_MOS') OR die( "Direct Access Is Not Allowed" );
$user = &JFactory::getUser();
$memid = $user->username;

//Prepare Data to post
$post_data['mem_id'] = $user->username ;
$post_data['pass'] = 'password' ;
$post_data['req'] = 'lgn';
$post_data['ent_fr'] = '1';

//Format info for posting
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);

//Initiate connection
$curl_connection = curl_init ('https://secure.gggolf.ca/summerlea/index.htm');
// Set options
curl_setopt($curl_connection, CURLOPT_URL,'https://secure.gggolf.ca/summerlea/index.htm');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

$post_data['mem_id'] = $memid ;
$post_data['pass'] = 'password' ;
$post_data['req'] = 'lgn';
$post_data['ent_fr'] = '1';
// Replaced with test data $post_data['pass'] = $user->password ;

// Post data
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

// Perform Request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);

// Close connection
curl_close($curl_connection);
?>

Solution 2:

<?php
defined('_JEXEC') OR defined('_VALID_MOS') OR die( "Direct Access Is Not Allowed" ); <-- Required for Joomla
$user = &JFactory::getUser(); <-- Connect to Joomla user component
$memid = $user->username;

<script type="text/javascript" language="javascript">
var memnum
memnum = $memid ;
?>

</script>
<form method='post' action="https://secure.gggolf.ca/summerlea/index.htm" name='logon'>

<input type='hidden' name='mem_id' value='<? php echo $memid;?>'>
// I also tried --> value= document.write(memnum) <-- To no avail
<input type='hidden' name='pass' value= 'password'>
<input type='hidden' name='req' value='lgn'>
<input type='hidden' name='ent_fr' value='1'>

<body onload="javascript:document.logon.submit();">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top