NEWBIE - how to pass options
Posted: Wed May 23, 2007 6:19 pm
feyd | Please use
and here is the PHP handler:[/syntax]
The questionable area is under calculate "shipping"
I am not sure if using a function is the right way to go or try and use a IF/ELSE statement? I need to have the selected option posted for the user to see what they selected and another variable posted to put in the paypal form.
Any help would be appreciated, like I said I am new and sorry if my question is not clear.
Split.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am new at PHP and need help with the following PayPal form. I am trying to pass shipping information to PayPal based on the users selection in the form. There are three choices with two results; 1. PDF 2. Mail 3. Gift Box - and the results would be, for choice one and two shipping would be $0 and for the Gift Box shipping would be $10.
Here is the form:
[syntax="html"]<form action="{path={city}_Spa_Where_You_Are/Confirm_Your_Purchase}" method="post" enctype="multipart/form-data">
<fieldset>
<legend class="h3">Fill out the Gift Gift Certificate</legend>
<div class="form_item"><label for="recipient">This Entitles:</label>
<input type="hidden" name="submitted" value="yes" />
<input type="text" name="recipient" id="recipient" maxlength="200" />
</div>
<div class="caption">Insert name of recipient as you want it to appear on the gift certificate.</div>
<div class="form_item"><label for="amount">To Amount (in US Dollars):</label>
<input type="text" name="amount" id="amount" />
</div>
<div class="caption">You may give any amount from $50-$1000. Your gift may be applied toward spa services, parking expenses and gratuities.</div>
<div class="form_item"><label for="sender">A Gift From:</label>
<input type="text" name="sender" id="sender" maxlength="100" />
</div>
<div class="caption">Insert the name of the giver(s) as you want it to appear on the certificate.</div>
<fieldset>
<legend class="h3">Shipping Options</legend>
<input type="hidden" name="shipping_amount" id="shipping_amount" />
<div class="form_item"><div class="label">How would you like you gift certificate delivered?</div><div class="input">
<select name="shipping">
<option value="nogo">Make a selection...</option>
<option value="PDF">Receive a PDF</option>
<option value="Mail">Mail it (No charge)</option>
<option value="Gift Box">Ship in a gift Box with Bow ($10.00 charge)</option>
</select>
Code: Select all
<?php
//Default to showing the form.
$goodtogo = false;
//Handle the incoming data.
if ($_POST['submitted'] == "yes"){
//Let's declare a submission value that tells us if we are fine.
$goodtogo = true;
//Validate the recipient.
try {
if (trim ($_POST['recipient']) == ""){
$goodtogo = false;
throw new exception ("Sorry, you must enter a recipient.<br />");
}
} catch (exception $e) {
?><span class="alert"><?php echo $e->getmessage(); ?></span><?php
}
//Validate the amount.
try {
if (trim ($_POST['amount']) == ""){
$goodtogo = false;
throw new exception ("Sorry, you must enter a amount.<br />");
}
} catch (exception $e) {
?><span class="alert"><?php echo $e->getmessage(); ?></span><?php
}
//Validate the sender.
try {
if (trim ($_POST['sender']) == ""){
$goodtogo = false;
throw new exception ("Sorry, you must enter a name.<br />");
}
} catch (exception $e) {
?><span class="alert"><?php echo $e->getmessage(); ?></span><?php
}
//Validate the select box.
try {
if ($_POST['shipping'] == "nogo"){
$goodtogo = false;
throw new exception ("Please make a selection.<br />");
}
} catch (exception $e) {
?><span class="error"><?php echo $e->getmessage(); ?></span><?php
}
// calculate shipping
function add_shipping () {
global $shipping_chargeVars;
$shipping_method = $_POST ['shipping'];
$ten = 10;
$free = 0;
$shipping_charge = ($shipping_method == "Gift_box");
echo $shipping_charge;
}
//Now, if there were no errors, we can output the results.
if ($goodtogo){
echo "To: " . $_POST['recipient'] . "<br />";
echo "From: " . $_POST['sender'] . "<br />";
echo "Amount: " . $_POST['amount'] . "<br />";
echo "Shipping: " . $_POST['shipping'] . "<br />";
?>I am not sure if using a function is the right way to go or try and use a IF/ELSE statement? I need to have the selected option posted for the user to see what they selected and another variable posted to put in the paypal form.
Any help would be appreciated, like I said I am new and sorry if my question is not clear.
Split.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]