Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

connect radiobuttons to script

Links for php scripts

Moderators: macek, egami, gesf

connect radiobuttons to script

Postby ipeteweb » Fri Mar 15, 2013 7:38 am

in payment script need to make 3 radio buttons
How can I create 3 radio buttons with different values and connect it to script, so price change depending on the selected radio button?

originally price have only one value:
$shoppingCart = array(
'price' => 0.30,
);

it work with it
$macFields = array(
'VK_AMOUNT' => to_banklink_ch ($shoppingCart['price']),
);

and form for button looks like:
Форма кнопки выглядит:
<form method="POST" action="<?php echo $banks[ $preferences['bankname'] ]['url']; ?>">
<?php
foreach ($macFields as $f => $v) {
echo '<input type="hidden" name="' . $f . '" value="' . htmlspecialchars ($v) . '" />' . "\n";
}
?>
<table cellpadding="0" cellspacing="0" border="0">

<tr>
<td colspan="2" align="center"><input type="submit" value="pay" /></td>
</tr>
</table>

</table>
</form>
ipeteweb
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Mar 15, 2013 7:33 am

Re: connect radiobuttons to script

Postby seandisanti » Fri Mar 15, 2013 8:12 am

Code: Select all
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>

creates a simple form with 2 options. They share the same name, so only one can be selected at a time. When sent via form, $_POST['sex'] will contain the value of the selected option as specified by the value attribute. So your decision making in the form processing page would look at $_POST['yourRadioButtonName'] (assuming you're posting form instead of using GET variables.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: connect radiobuttons to script

Postby ipeteweb » Sat Mar 16, 2013 1:29 pm

I would thank you so much if you help me finish it, i tried many times but my expierence do not let me finish this. Result in bank do not show price.


<?php

require_once 'config.php';
$shoppingCart = array(
'price' => 0.10,
'currency' => 'EUR',
'description' => 'comp',
'transaction_id' => 12345,
);
$macFields = array(
'VK_SERVICE' => '1001',
'VK_VERSION' => '008',
'VK_SND_ID' => to_banklink_ch ($preferences['my_id']),
'VK_STAMP' => to_banklink_ch ($shoppingCart['transaction_id']),
'VK_AMOUNT' => to_banklink_ch ($shoppingCart['price']),
'VK_CURR' => to_banklink_ch ($shoppingCart['currency']),
'VK_ACC' => to_banklink_ch ($preferences['account_number']),
'VK_NAME' => to_banklink_ch ($preferences['account_owner']),
'VK_REF' => '',
'VK_MSG' => to_banklink_ch ($shoppingCart['description']),
'VK_RETURN' => to_banklink_ch ('http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
dirname ($_SERVER['PHP_SELF']) . '/notify.php'),
);

$p = $banks[$preferences['bankname']]['charset_parameter'];
if ($p != '') {
$macFields[$p] = $banklinkCharset;
}

$key = openssl_pkey_get_private (
file_get_contents ($preferences['my_private_key']),
$preferences['my_private_key_password']
);

if (!openssl_sign (generateMACString ($macFields), $signature, $key)) {
trigger_error ("Unable to generate signature", E_USER_ERROR);
}

$macFields['VK_MAC'] = base64_encode ($signature);

header ("Content-Type: text/html; charset=" . $banklinkCharset);
?>
<form method="POST" action="<?php echo $banks[ $preferences['bankname'] ]['url']; ?>">
<?php
foreach ($macFields as $f => $v) {
echo '<input type="hidden" name="' . $f . '" value="' . htmlspecialchars ($v) . '" />' . "\n";
}

?>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<input type="radio" name="pay" value="25">25
</tr>
<tr>
<input type="radio" name="pay" value="50">50
</tr>
<tr>
<input type="radio" name="pay" value="75">75
</tr>
<tr>
<input type="radio" name="pay" value="100">100
</tr>


<tr>
<td colspan="2" align="center"><input type="submit" value="pay" /></td>
</tr>

</table>
</form>
ipeteweb
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Mar 15, 2013 7:33 am

Re: connect radiobuttons to script

Postby seandisanti » Mon Mar 18, 2013 7:40 am

here is an example to play with , I'm sure you can get it.
Code: Select all

<?php

if (!$_POST) { //display the form since we're not responding to it yet
    
echo '
<form method="POST" action="' 
$_SERVER['PHP_SELF'] . '">
<input type="text" name="cost" value="" /><br />    
<input type="radio" name="pay" value="25" />25<br />
<input type="radio" name="pay" value="50" />50<br />
<input type="radio" name="pay" value="75" />75<br />
<input type="radio" name="pay" value="100" />100<br />
<input type="submit" value="Multiply the text box by the radio button" />
</form>'
;
} else { 
//process form 
    //first for demonstration purposes; here's what we're working with:
    
echo '<pre>';
    
print_r($_POST);
    echo 
'</pre><br />';
    echo 
'The answer is ' $_POST['cost'] * $_POST['pay'];
}
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.