I currently have a form on my Wordpress shop which submits details to Paypal using the "Buy Now" button API. What I would like to do is based on the 'School' my customer selects on the form, I would like to submit the related Paypal e-mail address. I am currently storing the e-mail address related to the school in my database, so all I need to do is a SELECT from my database based on the selected school name.
I'd like to do this by submitting the form to a PHP class which then forwards the information to the Paypal API. My question is, as a PHP newbie, how do I do this? Here's the form code I have... how do I forward these fields to another PHP class which collects the selected dropdown field value and submits to Paypal?
Thanks in advance!!
<?php
class Template {
public function __construct() {
}
public function getForm($project_list, $business){
$require_mark = '<strong style="color:red;">*</strong>';
?>
<div id="payment_booking_main">
<form name="_xclick" id="payment_booking_form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- <form name="_xclick" id="payment_booking_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="hosted_button_id" value="7ACDDDD4URDK2" />
<!-- This is the paypal email that is sent. -->
<input type="hidden" name="business" value="<?php echo $business; ?>" />
<input type="hidden" name="a3" value="1">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" id="payment_booking_return_url" name="return" value="" />
<input type="hidden" id="payment_booking_notify_url" name="notify_url" value="">
<input type="hidden" id="payment_booking_total_amount" name="amount" value="0">
<input type="hidden" id="payment_booking_item_name" name="item_name" value="">
<input type="hidden" id="payment_booking_item_number" name="item_number" value="">
<!-- Where the project name option input is populated on form load -->
<div id="payment_booking_project_selectform">
<div class="payment_booking_line" style="heigth:20px !important;">
<span class="payment_booking_label">Project :</span>
<select id="payment_booking_project" name="payment_booking_project">
<?php
global $wpdb;
$sql = "SELECT * FROM `{$wpdb->prefix}payment_booking_project` WHERE project_status =1";
$project_list = $wpdb->get_results($sql);
foreach($project_list as $project){
echo '<option value="'.$project->id.'" amount="'.number_format($project->project_amount, 2).'" description="'.$project->project_description.'" price="'.$project->project_price.'">'.$project->project_name.'</option>';
}
?>
</select>
<span id="payment_booking_project_description" style="font-size:12px;"></span>
</div>
</div>
<div id="payment_booking_project_list"></div>
<div class="payment_booking_line">
<span class="payment_booking_label">Name <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_name" name="payment_booking_name" class="required" /></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Address <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><textarea id="payment_booking_address" name="payment_booking_address" class="required"></textarea></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Home Phone Number :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_phone" name="payment_booking_phone" /></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Email Address <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_email" name="payment_booking_email" class="required" /></span>
</div>
<div class="payment_booking_line">
<center>
<img id="img_submit" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" alt="PayPal — The safer, easier way to pay online." />
</center>
</div>
</form>
</div>
<?php
}
}
?>
Related
I have integrated payeezy payment gateway for one of my e-commerce site. I can easily pass the order details with price and quantity but not able to pass the total amount for the order details.
Here is the code which I am using---->
<form action="https://demo.globalgatewaye4.firstdata.com/pay" id="pay_now_form_1dcc971562" method="post">
<input name="x_login" type="hidden" value="XXX-XXXX-xxxxxxxxxx" />
<input name="x_show_form" type="hidden" value="PAYMENT_FORM" />
<input name="x_fp_sequence" type="hidden" value="14605299651823126780" />
<input name="x_fp_hash" type="hidden" value="PNB-1.0-eba46929895e57fc4254e9ef11cdbcbcf647334c" />
<input name="x_amount" type="hidden" />
<input name="x_currency_code" type="hidden" value="USD" />
<input name="x_test_request" type="hidden" value="TRUE" />
<input name="x_relay_response" type="hidden" value="" />
<input name="donation_prompt" type="hidden" />
<input name="button_code" type="hidden" value="Pay Now mySite" />
<?php
foreach ($_SESSION["cart_item"] as $item) {
?>
<input name="x_line_item" value="1<|><?php echo $item['title']; ?><|><?php echo $item['title']; ?><|>1<|><?php echo $item['price']; ?><|>YES" type="hidden">
<?php
} ?>
<div class="cpwrap">
<button type="button" >Pay Now</button>
</div>
</form>
If do I pass the value in
<input name="x_amount" type="hidden" value="99"/>
then I am getting error "Unable to proceed with payment " in the paymant gateway.
So how to resolve this issue. Please do some needful.
Thanks in advance.
with regards,
Sudhir
yes.. Finally after doing lot of research on payeezy got this link
Here is the code how to integrate payeezy with PHP with dynamic order details and total amount.
I have a form that collects data on a persons car (year, color, class, last 4 digits of vin. That same form also has information on the person registering for this event.
When the user clicks the paypal buy now button it should send an email to the person who is accepting the forms as well as redirect the user to paypal so the user can pay the registration fee.
You will see a submit button as well as a buy now button. I basically want the functionality of the submit but the redirection to paypal like the buy now button. Also not sure what the action should be on the form.
<div id="container">
<section id="register">
<form action="mail.php" method="post" accept-charset="utf-8" on>
<h4>Your Jeep</h4>
<div class="form-field">
<fieldset>
<label>Year</label>
<input value="" placeholder="Year" type="text" name="year">
</fieldset>
<fieldset>
<label>Color</label>
<input value="" placeholder="Color" type="text" name="color">
</fieldset>
<fieldset>
<label>Class</label>
<input value="" placeholder="Stock, Modified, Highly Modified" type="text" name="class">
</fieldset>
<!--------------------
<div class="form-field">
<fieldset>
<label>Class</label>
<select class="form-field">
<option value="Select Class">Select Class</option>
<option value="Stock">Stock</option>
<option value="Modified">Modified</option>
<option value="Highly Modified">Highly Modified</option>
</select>
</fieldset>
</div>
------------------------->
<fieldset>
<label>Last 4 digits of VIN</label>
<input value="" placeholder="Last 4 digits of VIN" type="text" name="vin">
</fieldset>
</div>
<h4>You</h4>
<div class="form-field">
<fieldset>
<label>Name</label>
<input value="" placeholder="Name" type="text" name="name">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Address</label>
<input value="" placeholder="Address" type="text" name="address">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>City</label>
<input value="" placeholder="City" type="text" name="city">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>State</label>
<input value="" placeholder="State" type="text" name="state">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Zip</label>
<input value="" placeholder="Zip" type="text" name="Zip">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Email</label>
<input value="" placeholder="Email" type="text" name="email">
</fieldset>
</div>
<div class="form-button">
<input type="submit" onclick="this.form.submit();"></div>
</form>
<div id="paykim">
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me#mybusiness.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Jeep Registration">
<input type="hidden" name="amount" value="10.00">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
<p>Clicking the Submit button will bring you to the official PayPal website where you will be able to send the $10 Registration Fee to </p>
<p id="ekim">Email of person accepting the registrations.</p>
<p id="confirm">You'll recieve a conformation email once your transaction is complete.</p>
</div>
</section>
</div>
http://jsfiddle.net/BsVv5/
I assume you will be store the data in a database. I recommend that first save your form data in the database, Once stored, create a checkout page by querying the database and creates the additional form of paypal. you will require documentation of ipn paypal for sending instant notifications.
https://developer.paypal.com/webapps/developer/docs/classic/products/instant-payment-notification/
Im having issues with a ''profile'' page where users will be able to change their username, email, name, password and so on but it seems to have conflicts when i have more than 1 form on the page as they all work individually?
I could be missing something obvious so if anyone could help id much appreciate it.
Base
<?php
require 'core/init.php';
include 'includes/overall/header.php';
?>
<h1><p>Hello <?php echo escape($user->data()->username); ?></a>!</p></h1>
<h4><p>You joined the MMOunition community <?php echo escape($user->data()->joined); ?></a></p></h4>
<alert_banner>
<?php
if(Session::exists('home')) {
echo '<p>', Session::flash('home'), '</p>';
}
?>
</alert_banner>
<br />
<form action="changeusername.php" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changepassword.php" method="post">
<div class="field">
<label for="password_current">Current password:</label>
<input type="password" name="password_current" id="password_current">
</div>
<div class="field">
<label for="password_new">New password:</label>
<input type="password" name="password_new" id="password_new">
</div>
<div class="field">
<label for="password_new_again">New password again:</label>
<input type="password" name="password_new_again" id="password_new_again">
<input type="submit" value="Change">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
</br>
<form action="changename.php" method="post">
<div class="field">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo escape($user->data()->name); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changeemail.php" method="post">
<div class="field">
<label for="email">Change email address:</label>
<input type="text" name="email" id="email" value="<?php echo escape($user->data()->email); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<?php
include 'includes/overall/footer.php';
?>
Hello You haven't mentioned what problem you actualy facing but this seems like the problem is the unique identification of a form at server side
Please see this post
Multiple HTML Forms on One Page
Hope this will help ;)
Have each form action set to the current page, and use hidden inputs to determine what action is being taken. Using this method will prevent the user from being dropped onto a different page, and puts the action being taken into a variable that you can use or manipulate.
If you want to have separate PHP scripts for actual functions, use includes or requires.
<form action="" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="hidden" name="action" value="changeUsername">
</div>
</form>
Then the PHP script gets the action from the POST and uses a switch to determine which functions to call.
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case "changeUsername":
changeUsername();
break;
case "changePassword":
...
As mentioned, if you want to have these functions in separate php files, you can use include or require.
This conveniently drops the user right back on the same page when they update information, so that they can make additional updates.
What I'm trying to do here is display my login information and once logged in display something else
Example is here
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1){
echo '
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMzM=" name="return">
<input type="hidden" value="1" name="39ea5446d876078c6f6221d396ef5bd4">
</form>
';
}
else
{
echo '
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="994c61f8ab4ccf23fe9dae6546a87089">
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
';
}
?>
No I know what I am doing wrong just have no clue how to fix it. the two
need to have a different generated number each time but how do i do this.
since this numbers are the same every time if i log in then out then try to log back in it will give me "Invalid Token"
When i go into the login template it gives me
this for login
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
and this for log out
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
Now if I replace the hidden fields that already have the pregenerated numbers with the php stuff above when i try to refresh my page it goes completely blank.
I am at a loss with this see as how I am not very advanced in php. any help anyone cant provide would be massively helpful..
why not try like this,
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1):
?>
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<?php else:
?>
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
<?php endif;?>
i have setup a form than when pressed the image submit button it sends the filled form to the buisness email.
Here is the script i have used for php linked from my html.
<?php
if(isset($_POST['submit'])) {
$emailbody = 'First Name = '.$_POST['Name']."\n"
.'Surname = '.$_POST['SName']."\n"
.'Email = '.$_POST['email']."\n"
.'Contact Number = '.$_POST['tel_no']."\n"
.'Adress Line 1 = '.$_POST['address_line_1']."\n"
.'Adress Line 2 = '.$_POST['address_line_2']."\n"
.'Town/City = '.$_POST['town_city']."\n"
.'County = '.$_POST['county']."\n"
.'Post Code = '.$_POST['Post_code']."\n"
.'Newsletter = '.$_POST['newsletter']."\n"
.'Events = '.$_POST['events']."\n"
mail('My email#gmail.com', 'Order Form', $emailbody);
} else {
header('location: Payment.html');
}
?>
The form on the html has been linked via a action. is there anything wrong with the script?
PS on pressing the image it is then forwarded to paypal payment page.
Cheers
Edit:
Here is the HTML Code:
<form name="form1" method="post" action="PaymentFormmail.php" align="left">
<section>
<h1>Basic Infomation:</h1>
<p>
<label for="SName">First Name:</label>
<input type="text" name="Name" id="Name" style="margin-left:50px;">
</p>
<p>
<label for="SName">Surname:</label>
<input type="text" name="SName" id="SName" style="margin-left:64px;">
</p>
<p>
<label for="email">Email Address</label>
<input type="text" name="email" id="email" style="margin-left:28px;">
</p>
<p>
<label for="tel_no">Contact Number:</label>
<input type="text" name="tel_no" id="tel_no" style="margin-left:14px;">
</p>
</section>
<section>
<h1>Billing Infomation:</h1>
<p>
<label for="address_line_1">Address line 1:*</label>
<input name="address_line_1" type="text" id="address_line_1" align="right" style="margin-left:20px;">
</p>
<p>
<label for="address_line_2">Address Line 2: </label>
<input type="text" name="address_line_2" id="address_line_2"style="margin-left:20px;">
</p>
<p>
<label for="town_city">Town/City:*</label>
<input type="text" name="town_city" id="town_city"style="margin-left:55px;">
</p>
<p>
<label for="county">County:*</label>
<input type="text" name="county" id="county"style="margin-left:73px;">
</p>
<p>
<label for="Post_code">Post Code:*</label>
<input type="text" name="Post_code" id="Post_code"style="margin-left:46px;">
</p>
<h1>News and Events:</h1>
<p>
<input name="newsletter" type="checkbox" id="newsletter" value="Yes">
<label for="newsletter">I wish to receive the monthly newsletter from Monster Computers UK</label>
</p>
<p>
<input name="events" type="checkbox" id="events" value="Yes">
<label for="events">I wish to receive any infomation about upcomming events</label>
</p>
</section>
</form>
<p>By Clicking Pay now you agree to the Terms of Service</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="monstercomputeruk#gmail.com">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" id="byoName" value="0">
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input name="submit" type="image" onClick="MM_validateForm('Name','','R','SName','','R','email','','R','address_line_1','','R','town_city','','R','county','','R','Post_code','','R');return document.MM_returnValue" src="images/buttons/Pay Now.png" alt="PayPal — The safer, easier way to pay online." border="0">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
Try changing
if(isset($_POST['submit']))
to
if(isset($_POST['SName']))
I think $_POST['submit'] doesn't work..
If this also fails then it means that the information isn't sent to your script.
In this case show us your html for the form used in the script.
EDIT
Using if(isset($_POST['submit'])) to not display echo when script is open is not working
EDIT AFTER HTML
in your javascript function called MM_validateForm
send your information using jquery POST to your mail script and remove the if clause checking if isset.
$.post("test.php", { name: "John", time: "2pm" } );
http://api.jquery.com/jQuery.post/
See examples section.