-1

Further to a question I asked earlier today I have posted the code below.

The question is how do I have two actions off of one form/one button. Some people recommended AJAX, and I have done some research but the solution is not clear to me.

Currently, the user clicks button on orderbelow.php and that sends an email to the website owner (send-order.php), the user then gets sent to completeyourorder.php. Here they click the button on the form that sends them to paypal.

I want to remove that extra step so that when they click on orderbelow.php the email is sent to the owner and the user is sent to paypal (keep in mind that two bits of information are sent to the paypal webpage as shown below, i.e. service and price).

I am a relatively inexperienced coder. I can see there are similar questions on here already but so far have not been able to determine exactly what I need to do in my particular situation.

Thanks.

This is the form code for orderbelow.php

<p>
<b>Personalised <?php echo $_GET['service']; ?></b>

<b>Price: &pound;<?php echo $_GET['p'];?></b>
</p>


<form name="orderform" action="send-order.php" onsubmit="return validateForm()" method="post">
<p>Name<br /><input name="clientname" value="<?echo $clientname;?>" type="text" style="width: 350px;" /></p>

<p>Email<br /><input name="email" value="<?echo $email;?>" type="text" style="width: 350px;" /></p>

<p>Date of Birth <i>(dd/mm/yyyy)</i><br /><input name="dateofbirth" value="<?echo $dateofbirth;?>" type="text" style="width: 350px;" /></p>

<p>Please tell me any questions you want covered in your session<br /><textarea name="questions" style="width: 500px; height: 200px;"><?echo str_replace("<br />","\r\n",$questions);?></textarea></p>

<p>Please tell me the first name of anyone you are asking about and describe any other relevant details you wish to share<br /><textarea name="comments" style="width: 500px; height: 200px;"><?echo str_replace("<br />","\r\n",$comments);?></textarea></p>


<p><br /><input type="hidden" name="service" value="<?
echo $_GET['service'];
?>" />

<input type="hidden" name="p" value="<?
echo $_GET['p'];
?>"
 />
<input type="submit" value="Order now" /></p>
 </form>

This is the form code for completeyourorder.php. It sends two pieces of data to populate Paypal checkout, i.e. the service "service", and the price "p".

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><p><input type="image" src="images/addtobasket.gif" name="submit" alt="Make payments with PayPal - fast, free and secure!" /><img alt="" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1" /><input type="hidden" name="add" value="1" /><input type="hidden" name="cmd" value="_cart" /><input type="hidden" name="business" value="xxxx@xxxxxx.co.uk" /><input type="hidden" name="item_name" value="<?php
echo $_GET['service'];
?>" /><input type="hidden" name="amount" value="<?php
echo $_GET['p'];
?>" /><input type="hidden" name="no_note" value="1" /><input type="hidden" name="currency_code" value="GBP" /><input type="hidden"  name="bn" value="PP-ShopCartBF" /></p></form>
user1098813
  • 41
  • 1
  • 6
  • 1
    you should have edited http://stackoverflow.com/posts/38719314/edit your other question http://stackoverflow.com/q/38719314/ instead with the code you're now using. This (almost) constitutes as a repost. – Funk Forty Niner Aug 02 '16 at 13:44

1 Answers1

0

Try an onSubmit with an AJAX call. The following pseudo-code (with some jquery):

$("#form_name").submit(function() {
  $.ajax:
  method: post
  action: php_email_function_url
  success: function() {
  redirect to new page
  };
)};
ccopland
  • 89
  • 4