Highlighted

Fillable Form: How to Include Multiple Actions for Submit Button?

Contributor ,
Feb 17, 2019

Copy link to clipboard

Copied

Right now when a customer hits "SUBMIT", the form he filled out gets emailed to me and a paypal page opens up.

But I added several options so what I need (ideally) is if a customer checks only one field and hits SUBMIT, he is taken to paypal page one.

If he checks two fields and hits SUBMIT he is taken to paypal page two.

And the same goes for 3 other options.

Any ideas?

sneedbreedley  wrote

OK, I simplified the procedure (hopefully). This is the order page and when SUBMIT is hit, the user is directed to the appropriate payment page. However I ALSO need the filled out form sent to my email address. Any ideas?

Order Form

The only way to do that is to use a very simple cart. You only need the form sent to you because at the moment you have no way of finding out what combination of products have been selected by the user, that is the job of paypal and paypal will send you a confirmation email detailing the product/s selected AFTER a payment has been made.

Below is the form code you need. Each product is stored in a php array - name="products[]" - see below, if selected.

<form name="products" action="product_process.php" method="post">

<input type="checkbox" value="Window Sticker" id="window_sticker" name="products[]"><label for="window_sticker">Window Sticker</label>

<br>

<input type="checkbox"  value="Car Shipper" id="car_shipper" name="products[]"><label for="car_shipper">Car Shipper</label>

<br>

<input type="checkbox" value="Dealer Invoice" id="dealer_invoice" name="products[]"><label for="dealer_invoice">Dealer Invoice</label>

<br>

<input type="checkbox" value="Retail Order Form" id="retail_order_form" name="products[]"><label for="retail_order_form">Retail Order Form </label>

<br>

<input type="checkbox" value="Tank Sticker (1967-1973 Corvette Only)" id="tank_sticker" name="products[]"><label for="tank_sticker"> Tank Sticker (1967-1973 Corvette Only) </label>

<br>

<input type="submit" name="submit" value="Submit">

</form>

Below is the php code that gets the chosen products from the form checkboxes. Insert this in a file named 'product_process.php' as that is the file name the form points to. Style it visually to suit what you need.

The products chosen are appended to the $products variable. We count the number of products chosen and append that to the variable $numberOfProducts - this is used to determine what the value should be for the paypal amount field.

We then loop through the selected products and assign the values to the appropriate paypal hidden fields. You need to use your paypal business email address in place of YOUR-PAYPAL-EMAIL-ADDRESS and your countries currency code in place of YOUR-COUNTRY-CURRENCY-CODE

This negates the necessity to have 5 seperate pages with 5 different paypal buttons.

TEST THIS FUNCTIONALITY OUT BEFORE DEPOLYING IT LIVE TO MAKE SURE IT DOES WHAT YOU NEED.

<?php

$products = $_POST['products'];

$numberOfProducts = count($products);

echo "<h3>Selected Products $numberOfProducts</h3>";

echo "<ul>";

foreach($products as $selectedProducts) {

echo "<li>$selectedProducts</li>";

}

echo "</ul>";

?>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="upload" value="1">

<input type="hidden" name="business" value="YOUR-PAYPAL-EMAIL-ADDRESS">

<input type="hidden" name="currency_code" value="YOUR-COUNTRY-CURRENCY-CODE">

<?php

$ii=1;

foreach($products as $item) {

echo "

<input type='hidden' name='quantity_$ii' value='1' >

<input type='hidden' name='item_name_$ii' value='{$item}' >";

?>

<?php if($numberOfProducts === 1) {

echo "<input type='hidden' name='amount_$ii' value='95' >";

}

elseif($numberOfProducts === 2) {

echo "<input type='hidden' name='amount_$ii' value='90' >";

}

elseif($numberOfProducts === 3) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 4) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 5) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

?>

<?php

$ii++;

}

?>

<input type="submit" id="check_out" value="CHECK OUT">

</form>

Views

887

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Fillable Form: How to Include Multiple Actions for Submit Button?

Contributor ,
Feb 17, 2019

Copy link to clipboard

Copied

Right now when a customer hits "SUBMIT", the form he filled out gets emailed to me and a paypal page opens up.

But I added several options so what I need (ideally) is if a customer checks only one field and hits SUBMIT, he is taken to paypal page one.

If he checks two fields and hits SUBMIT he is taken to paypal page two.

And the same goes for 3 other options.

Any ideas?

sneedbreedley  wrote

OK, I simplified the procedure (hopefully). This is the order page and when SUBMIT is hit, the user is directed to the appropriate payment page. However I ALSO need the filled out form sent to my email address. Any ideas?

Order Form

The only way to do that is to use a very simple cart. You only need the form sent to you because at the moment you have no way of finding out what combination of products have been selected by the user, that is the job of paypal and paypal will send you a confirmation email detailing the product/s selected AFTER a payment has been made.

Below is the form code you need. Each product is stored in a php array - name="products[]" - see below, if selected.

<form name="products" action="product_process.php" method="post">

<input type="checkbox" value="Window Sticker" id="window_sticker" name="products[]"><label for="window_sticker">Window Sticker</label>

<br>

<input type="checkbox"  value="Car Shipper" id="car_shipper" name="products[]"><label for="car_shipper">Car Shipper</label>

<br>

<input type="checkbox" value="Dealer Invoice" id="dealer_invoice" name="products[]"><label for="dealer_invoice">Dealer Invoice</label>

<br>

<input type="checkbox" value="Retail Order Form" id="retail_order_form" name="products[]"><label for="retail_order_form">Retail Order Form </label>

<br>

<input type="checkbox" value="Tank Sticker (1967-1973 Corvette Only)" id="tank_sticker" name="products[]"><label for="tank_sticker"> Tank Sticker (1967-1973 Corvette Only) </label>

<br>

<input type="submit" name="submit" value="Submit">

</form>

Below is the php code that gets the chosen products from the form checkboxes. Insert this in a file named 'product_process.php' as that is the file name the form points to. Style it visually to suit what you need.

The products chosen are appended to the $products variable. We count the number of products chosen and append that to the variable $numberOfProducts - this is used to determine what the value should be for the paypal amount field.

We then loop through the selected products and assign the values to the appropriate paypal hidden fields. You need to use your paypal business email address in place of YOUR-PAYPAL-EMAIL-ADDRESS and your countries currency code in place of YOUR-COUNTRY-CURRENCY-CODE

This negates the necessity to have 5 seperate pages with 5 different paypal buttons.

TEST THIS FUNCTIONALITY OUT BEFORE DEPOLYING IT LIVE TO MAKE SURE IT DOES WHAT YOU NEED.

<?php

$products = $_POST['products'];

$numberOfProducts = count($products);

echo "<h3>Selected Products $numberOfProducts</h3>";

echo "<ul>";

foreach($products as $selectedProducts) {

echo "<li>$selectedProducts</li>";

}

echo "</ul>";

?>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="upload" value="1">

<input type="hidden" name="business" value="YOUR-PAYPAL-EMAIL-ADDRESS">

<input type="hidden" name="currency_code" value="YOUR-COUNTRY-CURRENCY-CODE">

<?php

$ii=1;

foreach($products as $item) {

echo "

<input type='hidden' name='quantity_$ii' value='1' >

<input type='hidden' name='item_name_$ii' value='{$item}' >";

?>

<?php if($numberOfProducts === 1) {

echo "<input type='hidden' name='amount_$ii' value='95' >";

}

elseif($numberOfProducts === 2) {

echo "<input type='hidden' name='amount_$ii' value='90' >";

}

elseif($numberOfProducts === 3) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 4) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 5) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

?>

<?php

$ii++;

}

?>

<input type="submit" id="check_out" value="CHECK OUT">

</form>

Views

888

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 17, 2019 0
Adobe Community Professional ,
Feb 17, 2019

Copy link to clipboard

Copied

this does it based on whether one checkbox is checked or not:

<script>
$
('#checkboxid').on('change', function(){
  
if ($(this).is(':checked')) {
  $
('form').attr('action', 'action1.php');
  
} else {
  $
('form').attr('action', 'action2.php');
  
}
});
</script>

Are we talking about a specefic checkbox or any one of several ??? Also it'll be be easier for people to help if you can post the entire page or a link to the page....

Paul-M, ACP

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2019 0
Adobe Community Professional ,
Feb 17, 2019

Copy link to clipboard

Copied

Another jQuery example (put your checkboxes inside a container with the id=checkbox_container), checks for more than 1 checkbox checked:

$('#checkbox_container input').change(function() {

   if ($("#checkbox_container input:checkbox:checked").length > 1) {

      $('form').attr('action', 'action1.php');

   } else {

      $('form').attr('action', 'action2.php');

   }

});

Post your full code or llink then we give you a full solution ....

Paul-M, ACP

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2019 1
Contributor ,
Feb 17, 2019

Copy link to clipboard

Copied

Here is an example page. At the very bottom of the page, (before the Personal Info section), are the check boxes are for the documents requested. When SUBMIT is hit, I need the page to jump to one of 5 paypal pages depending on how many boxes are checked.

1959 Corvette Options

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2019 0
Adobe Community Professional ,
Feb 17, 2019

Copy link to clipboard

Copied

Just the five checkboxess are we talking about - there's a larger batch of checkboxed further up too?

Paul-M, ACP

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2019 0
Adobe Community Professional ,
Feb 17, 2019

Copy link to clipboard

Copied

Ok, I'm with you now .... these five options:

Window Sticker

Car Shipper

Dealer Invoice

Retail Order Form

Tank Sticker (1967-1973 Corvette Only)

ANY one checked : form action 1

ANY two checked : form action 2

ANY three checked  form action 3

ANY four checked : fomr action 4

ANY five checked : form action 5

wrap that section in a div with id="checkbox_container"  like this:

<div id="checkbox_container">

Please select the documents you are interested in from the list below:<br>

<label>

                <input type="checkbox" code="option_" value="Window Sticker" name="option_1">

                Window Sticker</label>

            <br>

              <label>

                <input type="checkbox" code="option_" value="Car Shipper" name="option_2">

                Car Shipper</label>

            <br>

              <label>

                <input type="checkbox" code="option_" value="Dealer Invoice" name="option_3">

                Dealer Invoice </label>

            <br>

              <label>

                <input type="checkbox" code="option_" value="Retail Order Form" name="option_4">

                Retail Order Form </label>

           

            <br><label><input type="checkbox" code="option_" value="Tank Sticker (1967-1973 Corvette Only)" name="option_8">

            Tank Sticker (1967-1973 Corvette Only) </label><br><br>

</div>

Your script then is like this:

<script>

$( document ).ready(function() {

$('#checkbox_container input').change(function() {

if ($("#checkbox_container input:checkbox:checked").length === 1) {

$('form').attr('action', 'action1.php');

}

else if ($("#checkbox_container input:checkbox:checked").length === 2) {

$('form').attr('action', 'action2.php');

}

else if ($("#checkbox_container input:checkbox:checked").length === 3) {

$('form').attr('action', 'action3.php');

}

else if ($("#checkbox_container input:checkbox:checked").length === 4) {

$('form').attr('action', 'action4.php');

}

else if ($("#checkbox_container input:checkbox:checked").length === 5) {

$('form').attr('action', 'action5.php');

}

});

});

</script>

change action1.php, action2.php etc as required ....

Paul-M, ACP

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2019 1
LEGEND ,
Feb 18, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

Right now when a customer hits "SUBMIT", the form he filled out gets emailed to me and a paypal page opens up.

But I added several options so what I need (ideally) is if a customer checks only one field and hits SUBMIT, he is taken to paypal page one.

If he checks two fields and hits SUBMIT he is taken to paypal page two.

And the same goes for 3 other options.

Any ideas?

When you say 'paypal page one' what do you mean - normally a paypal account is associated with an email address and will go through to the checkout gateway, according to that email address, not according to how many checkboxes are checked.

If you mean you want to be taken to an internal paypal page on your website:

paypal_1.php

paypal_2.php

paypal_3.php

paypal_4.php

paypal_5.php

Then use the solution Energize provided, although you could streamline it a bit as below:

$( document ).ready(function() {

$('#checkbox_container input').change(function() {

var countChecked = $("#checkbox_container input:checkbox:checked").length;

$('form').attr('action', 'paypal_' + countChecked + '.php');

});

});

Energizes if/else if code is a bit more 'human' readable and understandable if you're not too familiar with coding.

So just to clarify either solution will work:

if 1 random checkbox is checked and the form button is clicked paypal_1.php will be evoked

if 2 random checkboxes are checked and the form button is clicked paypal_2.php will be evoked

if 3 random checkboxes are checked and the form button is clicked paypal_3.php will be evoked

etc

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 1
Contributor ,
Feb 18, 2019

Copy link to clipboard

Copied

Where does the script go?

In the following section near the top of the page?:

<script src="css-winvoices/respond.min.js"></script>

</head>

<body>

<div class="gridContainer">

<div id="logo"><a href="index.php"><img src="images/logo-59corvette.jpg" alt="1959 Corvette Window Sticker Options"></a></div>

    <?php include('navigation.php'); ?>  

<div>

  <div id="text1">

<form action="contact.php" method="post" name="form4">

or somewhere on the contact.php page?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
LEGEND ,
Feb 18, 2019

Copy link to clipboard

Copied

The script would go in the same page as your form that has the checkboxes:

You can insert the <script></script> block before the closing </head> tag or even include it before the closing </body> tag of your page. It's assumed you have the jQuery library linked to the page.

<script>

$( document ).ready(function() {

$('#checkbox_container input').change(function() {

var countChecked = $("#checkbox_container input:checkbox:checked").length;

$('form').attr('action', 'paypal_' + countChecked + '.php');

});

});

</script>

Wrap your form in a <div> with the id of 'checkbox_container': (You can rename this if you want but then dont forget to re-name the reference to it in the <script> block. You obviously leave the 'action' of the form blank as that will be generated automatically by the <script>

<div id="checkbox_container">

<form action="" method="post" name="form4">

CHECKBOXES GO HERE

</form>

</div>

<!-- end checkbox_container -->

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
Contributor ,
Feb 18, 2019

Copy link to clipboard

Copied

That seems to work but now the filled-in form is NOT being sent to my email address!

Here is the code on the contact page:

<?php 

if ($_POST){ 

    if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)){

echo ('<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">

            <b>' . $_POST['email'] . '</b> Email is not valid. Return to previous page and enter a valid email.

          </div>');

        } else { 

        $body = "";

$Miscellaneous = $_POST['Miscellaneous'];

if (preg_match("~\bhttp\b~", $Miscellaneous) or preg_match("~\bHTTP\b~", $Miscellaneous)) {

exit;

}

else {

        foreach ($_POST as $param_name => $param_val) { 

            $body .= "$param_name: $param_val\n"; 

        } 

}

        $headers = 'From: ' .$_POST['email']; 

        if (mail("steve@videoclassics.com", "Contact form submitted.", $body, $headers)) { 

            header('Location: http://www.winvoices.com/paymentform.php'); 

  } else { 

  $message = 'Sorry an error occurred. Please try again later.'; 

        } 

    } 

?> 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
LEGEND ,
Feb 18, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

That seems to work but now the filled-in form is NOT being sent to my email address!

Here is the code on the contact page:

Well it won't which is why I was asking what it is you are trying to do.

The form action instead of going to

contact.php where your php form processing script is, it's instead going to:

paypal_1.php or paypal_2.php etc determined by how many checkboxes have been clicked

I dont know what your workflow is or what's on/in paypal_1.php, paypal_2.php etc

Infact I have no idea where paypal figures in this as paypal requires the form to point to its gateway?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 1
Adobe Community Professional ,
Feb 18, 2019

Copy link to clipboard

Copied

I'm likewise very confused as to how this is supposed to work.  Ideally, this should be taking place on a shopping cart with variables that people  select directly on the cart page. 

Shopping Cart Software Solutions for eCommerce Sites - PayPal US

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
Contributor ,
Feb 18, 2019

Copy link to clipboard

Copied

We don't want a shopping cart. We charge by the number of documents. When a customer enters a correct return email address on the fillable form and hits SUBMIT, he should be directed to a new page on my site with the correct paypal PAY NOW button. This now works. But The fillable form should be sent  to my email address as per the contact page but it no longer does.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
LEGEND ,
Feb 18, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

But The fillable form should be sent  to my email address as per the contact page but it no longer does.

Then put the php form processing script at the top of each one of your files:

paypal_1.php

paypal_2.php

paypal_3.php

etc

That will send the details from the form that the user has filled out on the previous page.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
Contributor ,
Feb 18, 2019

Copy link to clipboard

Copied

At the top of each of what files?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
Adobe Community Professional ,
Feb 18, 2019

Copy link to clipboard

Copied

A form submit button can perform only one action.  

<form action="form-processing-script.php">

Your form processing script has to be programmed to perform all of the following directives:

  • thwart spam and robots,
  • validate form fields,
  • sanitize data,
  • calculate number of documents requested,
  • send user to the appropriate URL based on number of documents,
  • send an e-mail to the site owner.

That's a good deal of script writing.  How good are you with PHP programming?

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
LEGEND ,
Feb 18, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

At the top of each of what files?

The files where your palpal buttons are.

Presumably the user fills in the form details/checkboxes which is then directed to the page where the paypal button is housed depending on what boxes have been checked on the form?

If you insert the php form processing script at the very top of each of those pages before anything else on the page the form details will get mailed to you and then the user presumably will be left to click on the paypal button which takes them to the paypal gateway where they can pay.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
Contributor ,
Feb 18, 2019

Copy link to clipboard

Copied

I have a separate Contact page that contained all the code directing the user to the Success page and emailing me a copy of the fillable form after he filled it out and hit SUBMIT.

I still want to receive the filled out form but now I want the user to be directed to one of 5 pages depending on whether he selected 1, 2, 3, 4, or 5 documents.

The code that Energize and osgood sent me worked but it seemed to conflict with the code on the contact page because I no longer receive the filled out form.

Again, here is the code from the Contact page:

<?php

if ($_POST){

    if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)){

echo ('<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">

            <b>' . $_POST['email'] . '</b> Email is not valid. Return to previous page and enter a valid email.

          </div>');

        } else {

        $body = "";

$Miscellaneous = $_POST['Miscellaneous'];

if (preg_match("~\bhttp\b~", $Miscellaneous) or preg_match("~\bHTTP\b~", $Miscellaneous)) {

exit;

}

else {

         foreach ($_POST as $param_name => $param_val) {

            $body .= "$param_name: $param_val\n";

        }

}

        $headers = 'From: ' .$_POST['email'];

        if (mail("steve@videoclassics.com", "Contact form submitted.", $body, $headers)) { 

            header('Location: http://www.winvoices.com/success.php'); 

  } else {

  $message = 'Sorry an error occurred. Please try again later.';

        }

    }

}

?>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
LEGEND ,
Feb 19, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

I have a separate Contact page that contained all the code directing the user to the Success page and emailing me a copy of the fillable form after he filled it out and hit SUBMIT.

I still want to receive the filled out form but now I want the user to be directed to one of 5 pages depending on whether he selected 1, 2, 3, 4, or 5 documents.

The code that Energize and osgood sent me worked but it seemed to conflict with the code on the contact page because I no longer receive the filled out form.

Again, here is the code from the Contact page:

As I keep saying you need to include the processing script at the top of your five pages which contain the paypal buttons.

However its a pointless workflow as you will receive the details from the form BEFORE the user has clicked the paypal button which takes them to the paypal website. If you include a redirect then they wont even get a chance to click the paypal button.

All this needs to be done AFTER the paypal payment has gone through so you need to set up the paypal button to include the information that you require from the form and use a 'success' url  AFTER the payment has been made.

A paypal button can contain a number of restricted variables, one of which I am sure is an option to include a url to a 'success' page on your website AFTER a payment has been made.

At the moment your workflow isnt making too much sense as you are trying to get the information from the form and redirect the user BEFORE a payment has been made.

A paypal workflow is as follows. You append all the information required to the paypal button. That information is hugely restrictive typically a price, quantity, description plus a few more options if needed, etc. The user clicks the paypal button and is taken to the paypal website. A payment is made and you then receive an email with details of what has been purchased. The user is then redirected back to your website, either to continue shopping or to a success page.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 19, 2019 1
Contributor ,
Feb 19, 2019

Copy link to clipboard

Copied

OK, I simplified the procedure (hopefully). This is the order page and when SUBMIT is hit, the user is directed to the appropriate payment page. However I ALSO need the filled out form sent to my email address. Any ideas?

Order Form

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 19, 2019 0
LEGEND ,
Feb 19, 2019

Copy link to clipboard

Copied

sneedbreedley  wrote

OK, I simplified the procedure (hopefully). This is the order page and when SUBMIT is hit, the user is directed to the appropriate payment page. However I ALSO need the filled out form sent to my email address. Any ideas?

Order Form

The only way to do that is to use a very simple cart. You only need the form sent to you because at the moment you have no way of finding out what combination of products have been selected by the user, that is the job of paypal and paypal will send you a confirmation email detailing the product/s selected AFTER a payment has been made.

Below is the form code you need. Each product is stored in a php array - name="products[]" - see below, if selected.

<form name="products" action="product_process.php" method="post">

<input type="checkbox" value="Window Sticker" id="window_sticker" name="products[]"><label for="window_sticker">Window Sticker</label>

<br>

<input type="checkbox"  value="Car Shipper" id="car_shipper" name="products[]"><label for="car_shipper">Car Shipper</label>

<br>

<input type="checkbox" value="Dealer Invoice" id="dealer_invoice" name="products[]"><label for="dealer_invoice">Dealer Invoice</label>

<br>

<input type="checkbox" value="Retail Order Form" id="retail_order_form" name="products[]"><label for="retail_order_form">Retail Order Form </label>

<br>

<input type="checkbox" value="Tank Sticker (1967-1973 Corvette Only)" id="tank_sticker" name="products[]"><label for="tank_sticker"> Tank Sticker (1967-1973 Corvette Only) </label>

<br>

<input type="submit" name="submit" value="Submit">

</form>

Below is the php code that gets the chosen products from the form checkboxes. Insert this in a file named 'product_process.php' as that is the file name the form points to. Style it visually to suit what you need.

The products chosen are appended to the $products variable. We count the number of products chosen and append that to the variable $numberOfProducts - this is used to determine what the value should be for the paypal amount field.

We then loop through the selected products and assign the values to the appropriate paypal hidden fields. You need to use your paypal business email address in place of YOUR-PAYPAL-EMAIL-ADDRESS and your countries currency code in place of YOUR-COUNTRY-CURRENCY-CODE

This negates the necessity to have 5 seperate pages with 5 different paypal buttons.

TEST THIS FUNCTIONALITY OUT BEFORE DEPOLYING IT LIVE TO MAKE SURE IT DOES WHAT YOU NEED.

<?php

$products = $_POST['products'];

$numberOfProducts = count($products);

echo "<h3>Selected Products $numberOfProducts</h3>";

echo "<ul>";

foreach($products as $selectedProducts) {

echo "<li>$selectedProducts</li>";

}

echo "</ul>";

?>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="upload" value="1">

<input type="hidden" name="business" value="YOUR-PAYPAL-EMAIL-ADDRESS">

<input type="hidden" name="currency_code" value="YOUR-COUNTRY-CURRENCY-CODE">

<?php

$ii=1;

foreach($products as $item) {

echo "

<input type='hidden' name='quantity_$ii' value='1' >

<input type='hidden' name='item_name_$ii' value='{$item}' >";

?>

<?php if($numberOfProducts === 1) {

echo "<input type='hidden' name='amount_$ii' value='95' >";

}

elseif($numberOfProducts === 2) {

echo "<input type='hidden' name='amount_$ii' value='90' >";

}

elseif($numberOfProducts === 3) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 4) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

elseif($numberOfProducts === 5) {

echo "<input type='hidden' name='amount_$ii' value='75' >";

}

?>

<?php

$ii++;

}

?>

<input type="submit" id="check_out" value="CHECK OUT">

</form>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 19, 2019 1