pstanbra Posted February 14, 2007 Share Posted February 14, 2007 Hi - I've found a great little script to use as form validation. However - on my form - the action needs to be changed to PHP_SELF. Seems the form data is pushed into an array and then error checking is done on this. In the added code, there is a section here; // no errors! redirect the user to the thankyou page (or whatever) else { } } So my question is - how do I send my form variables (now error checked) to www.Paypal.com/webscr My Form Page; <?php $errors = array(); // set the errors array to empty, by default $fields = array(); // stores the field values $success_message = ""; if (isset($_POST['submit'])) { // import the validation library require("validation.php"); $rules = array(); // stores the validation rules $rules[] = "range<100,number_range_less_than,Please enter a number less than 100."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } // no errors! redirect the user to the thankyou page (or whatever) else { *******need to send my form info to paypal ************ } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>PHP Validation Demo</title> <style type="text/css"> <!-- body,p,table,td,input,select { font-family: arial; font-size: 8pt; } .demoTable { background-color: #efefef; width: 400px; } .error { border: 1px solid red; background-color: #ffffee; color: #660000; width: 400px; padding: 5px; } .notify { border: 1px solid #336699; background-color: #ffffee; color: #336699; width: 400px; padding: 5px; } --> </style> </head> <body> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p><b><u>PHP Validation Demo</u></b></p> <p> This form contains all the validation options that are offered by the validation.php function library. To see how the code works, <a href="file:///C|/Documents and Settings/stanbrap/Desktop/php_validation/php_validation.zip">download the source code here</a>. </p> <?php // if $errors is not empty, the form must have failed one or more validation // tests. Loop through each and display them on the page for the user if (!empty($errors)) { echo "<div class='error'>Please fix the following errors:\n<ul>"; foreach ($errors as $error) echo "<li>$error</li>\n"; echo "</ul></div>"; } if (!empty($success_message)) { echo "<div class='notify'>$success_message</div>"; } ?> <p> </p> <table class="demoTable"> <tr> <td>nter a number less than 100:</td> <td><input type="text" name="number_range_less_than" value="<?=$fields['number_range_less_than']?>" /></td> </tr> </table> <p><i>Length of field input</i></p> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<?PHP echo $business;?>"> <input type="hidden" name="item_name" value="Donation"> <input type="hidden" name="item_number" value="donation"> <input type="hidden" name="currency_code" value="<?PHP echo $currency_code;?>"> <input type="hidden" name="notify_url" value="<?PHP echo $notify_url;?>"> <input type="hidden" name="return" value="<?PHP echo $return;?>"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> <p><input type="submit" name="submit" value="SUBMIT" /></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 14, 2007 Share Posted February 14, 2007 you need to look at curl library - its in the manual... http://uk2.php.net/manual/en/ref.curl.php or you can set the headers - last one being Loction: 'paypalurl' Quote Link to comment Share on other sites More sharing options...
pstanbra Posted February 14, 2007 Author Share Posted February 14, 2007 Is this really neccessary? I only want to do the same as click on submit on a form and send/POST to the paypal link. The only difference is that my form fields are sent to PHP_self for checking - once checks are correct - the function should be the same post for to paypal Quote Link to comment Share on other sites More sharing options...
s0c0 Posted February 14, 2007 Share Posted February 14, 2007 You should use javascript for form validation, no server load that way. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2007 Share Posted February 14, 2007 "Is this really neccessary? I only want to do the same as click on submit on a form and send/POST to the paypal link. The only difference is that my form fields are sent to PHP_self for checking - once checks are correct - the function should be the same post for to paypal" So at the end of the checking, use the header('Location'); command. "You should use javascript for form validation, no server load that way." You can't use ONLY client-side validation, you must have some server-side. Quote Link to comment Share on other sites More sharing options...
pstanbra Posted February 14, 2007 Author Share Posted February 14, 2007 So at the end of the checking, use the header('Location'); command. Yes I did think that but simply adding that takes you to paypals page - as apposed to having fields sent to the paypal script by the form post command. how do i use header yet send all the fields from the form now stored in the array Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2007 Share Posted February 14, 2007 Doesn't Paypal accept the fields as GET also? Quote Link to comment Share on other sites More sharing options...
pstanbra Posted February 14, 2007 Author Share Posted February 14, 2007 not sure but still how do I send them. so far i got header ('location: https://www.paypal.com/cgi-bin/webscr' .$_GET[$fields]); but this doesnt work Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2007 Share Posted February 14, 2007 you have to send them as a query string, like you do with a URL. url.com/foo.php?foo=bar&bar=foo Quote Link to comment Share on other sites More sharing options...
pstanbra Posted February 14, 2007 Author Share Posted February 14, 2007 i give up - ill look at javascript Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.