Jump to content

PHP


emilysnothere

Recommended Posts

What I am trying to accomplish is a form that once submitted:

[*]Validations the form information

[*]Stores the form information in a session

[*]forwards the user to paypal to pay

 

At the moment I can either set the payal link as the form action which successfully takes the user to the paypal page to pay OR validate the form etc but when the user gets forwarded to paypal it takes them to the home page, not the payment page.

 

An idea ive had is creating a hidden form once the form has been validated with no errors and after the information is stored in a session. This form would be automatically submitted using javascript and would need the level passed to it from the original form. This, however seems like a long way of going about it and is also not working yet.

 

Does anyone have any ideas or solutions to this problem?

 

Here is my code which creates the form and displays it on the page

 

<?php
session_start();
/**
* register.php
* creates a new user for UBT news letters that will get stored in the database with an automatic level of 0 until they have been approved or disapproved.
* with the level of 0 they can log in but cannot view any details in the admin area. 
*/
require_once '../includes/config.php';            //database details
require_once '../includes/DatabaseClass.php';     //connects to the database ($dbConArray)
require_once '../includes/HtmlClass.php';         
require_once '../includes/FormClass2.php';        //formClass2.php connects to the database (formClass.php does not - form contact pages etc that dont need database)
require_once '../includes/class.phpmailer.php';
require_once '../includes/recaptchalib.php';

$privatekey = "6LfTwwsAAAAAAPO_xXInnEd_bOByzcQk0lnB7CZL";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

$countryarray = array ('argentina', 'australia', 'barbados', 'canada', 'denmark', 'france', 'germany', 'ireland', 'italy', 'jamaica', 'netherlands',
                           'newzealand', 'spain', 'sweden', 'switzerland', 'trinidadandtobago', 'unitedkingdom', 'unitedstates');
//check that the country is set
//filter $_GET for country of the page
if (isset($_GET['country']) && ctype_alnum($_GET['country'])){
    //test to make sure $country is equal to once of the countries allowed to register on the site. if not return to select country.
    //this can probably be changed to use the above array.
    //ALSO
    //check the country against the $country value and edit the detail on the page according to this
    //the gold and silver costs will change depending ont eh country
    //$country2 will be displayed on screen and in the email but $country will get inserted into the database.
    if($_GET['country'] == 'argentina'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                          'Gold $US359.00'=>'2');
    $country2='Argentina';
    
    }else if($_GET['country'] == 'australia'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $A19900 + GST'=>'1',
                      'Gold $A39900 + GST'=>'2');
        $country2='Australia';
        
    }else if($_GET['country'] == 'barbados'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='Barbados';
        
    }else if($_GET['country'] == 'canada'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='Canada';
        
    }else if($_GET['country'] == 'denmark'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Denmark';
        
    }else if($_GET['country'] == 'france'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='France';
        
    }else if($_GET['country'] == 'germany'){
       $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Germany';
        
    }else if($_GET['country'] == 'ireland'){
        $country = $_GET['country'];
        $selectArray = array ('Silver £119.00'=>'1',
                      'Gold £229.00'=>'2');
        $country2='Ireland';
        
    }else if($_GET['country'] == 'italy'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Italy';
        
    }else if($_GET['country'] == 'jamaica'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='Jamaica';
        
    }else if($_GET['country'] == 'netherlands'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Netherlands';
        
    }else if($_GET['country'] == 'newzealand'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold $NZ489.00'=>'2');
        $country2='New Zealand';
        
    }else if($_GET['country'] == 'saintvincent'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='Saint Vincent';

   }else if($_GET['country'] == 'spain'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Spain';
        
    }else if($_GET['country'] =='sweden'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Sweden';
        
    }else if($_GET['country'] == 'switzerland'){
        $country = $_GET['country'];
        $selectArray = array ('Silver €129.00'=>'1',
                      'Gold €259.00'=>'2');
        $country2='Switzerland';
        
    }else if($_GET['country'] =='trinidadandtobago'){
        $country = $_GET['country'];
        $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='Trinidad and Tobago';
        
    }else if($_GET['country'] == 'unitedkingdom'){
        $country = $_GET['country'];
        $selectArray = array ('Silver £119.00'=>'1',
                      'Gold £229.00'=>'2');
        $country2='United Kingdom ';
        
    }else if($_GET['country'] == 'unitedstates'){
       $country = $_GET['country'];
       $selectArray = array ('Silver $US179.00'=>'1',
                      'Gold $US359.00'=>'2');
        $country2='United States';
    }else{
        header('Location: selectCountry.php');
    }

}


//create a new form
$form = new makeForm($dbConArray);              //connect to the database

//messages for required fields. Will change to red once submitted if the field is empty or incorrect. Disappears if the field is correct
// will also change with javascript validation - requires formValidation.js
$form->messageArray['email'] = '*';
$form->messageArray['pwd'] = '*';
$form->messageArray['fname'] = '*';
$form->messageArray['lname'] = '*';
$form->messageArray['companyname'] = '*';
$form->messageArray['companysize'] = '*';
$form->messageArray['address'] = '*';
$form->messageArray['suburb'] = '*';
$form->messageArray['city'] = '*';
$form->messageArray['postcode'] = '';
$form->messageArray['phone'] = '*';
$form->messageArray['fax'] = '';

//if sentForm=1 the form is displayed otherwise the form is hidden and the sent message is displayed upon submit.
$sentForm=1;

//run this script if the form is submitted. - will check fields on serverside.
//if there are no errors the data will be entered into the database and an email will be sent to unex telling them theres a user to process
if($_POST['submit']){
   // store all the values in an array to use when checking the data and when re-writing the form
    $form->storeValues($_POST);
    //check each field
    $form->checkEmpty('os0');
    $form->checkUsername('email');  //checks this does not already exist in database. also calls the checkEmail function
    $form->checkEmpty('pwd');     //encrypts password
    $form->checkEmpty('fname');
    $form->checkEmpty('lname');
    $form->checkEmpty('companyname');
    $form->checkEmpty('address');
    $form->checkEmpty('suburb');
    $form->checkEmpty('city');
    $form->checkNotRequired('postcode');
    $form->checkEmpty('phone');
    $form->checkNotRequired('fax');

    
// check if there were any errors
//if no errors, run the insert query and return the user to this page
    if($form->totalErrors == 0){
        //if ($resp->is_valid) {
            //if the form and captcha are valid store all the variables in the session before redirecting to paypal.
            //paypal will direct back to the confirmation.php page if the payment goes through
            //on load of the page the users details from the session will be stored in the database
            $_SESSION['membershiplevel'] = $_POST['os0'];
            $_SESSION['email'] = $_POST['email'];
            $_SESSION['password'] = $_POST['pwd'];
            $_SESSION['firstname'] = $_POST['fname'];
            $_SESSION['lastname'] = $_POST['lname'];
            $_SESSION['company'] = $_POST['companyname'];
            $_SESSION['address'] = $_POST['address'];
            $_SESSION['suburb'] = $_POST['suburb'];
            $_SESSION['city'] = $_POST['city'];
            $_SESSION['storedcountry'] = $country2;
            $_SESSION['postcode'] = $_POST['postcode'];
            $_SESSION['phoneno'] = $_POST['phoneno'];
            $_SESSION['fax'] = $_POST['fax'];
            
            
            echo $_SESSION['membershiplevel'];
            echo $_SESSION['email'];
            echo $_SESSION['password'];
            echo $_SESSION['firstname'];
            echo $_SESSION['lastname'];
            echo $_SESSION['company'];
            echo $_SESSION['address'];
            echo $_SESSION['suburb'];
            echo $_SESSION['city'];
            echo $_SESSION['storedcountry'];
            echo $_SESSION['postcode'];
            echo $_SESSION['phoneno'];
            echo $_SESSION['fax'];
                       
            //Make hidden form that will submit once the original form has been submitted correctly and validated with information stored in session
            //this form will take user to paypal
            //needs to get the membership level from the original form
            
            $hiddenform = new makeForm($dbConArray);              //connect to the database
            if($_GET['country'] == 'argentina'){
                $hiddenform->usapaypal();
                
            }else if($_GET['country'] == 'australia'){
                $hiddenform->nzpaypal();   
                
            }else if($_GET['country'] == 'barbados'){
                $hiddenform->usapaypal();
                
            }else if($_GET['country'] == 'canada'){
                $hiddenform->usapaypal();
                
            }else if($_GET['country'] == 'denmark'){
                $hiddenform->europaypal();
                
            }else if($_GET['country'] == 'france'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] == 'germany'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] == 'ireland'){
                $hiddenform->ukpaypal();
                
            }else if($_GET['country'] == 'italy'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] == 'jamaica'){
                $hiddenform->usapaypal();
                
            }else if($_GET['country'] == 'netherlands'){
                $hiddenform->europaypal(); 
                
            }else if($_GET['country'] == 'newzealand'){
                $hiddenform->nzpaypal();   
                
            }else if($_GET['country'] == 'saintvincent'){
                $hiddenform->usapaypal();
            
            }else if($_GET['country'] == 'spain'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] =='sweden'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] == 'switzerland'){
                $hiddenform->europaypal();   
                
            }else if($_GET['country'] =='trinidadandtobago'){
                $hiddenform->usapaypal();
                
            }else if($_GET['country'] == 'unitedkingdom'){
                $hiddenform->ukpaypal();
                
            }else if($_GET['country'] == 'unitedstates'){
                $hiddenform->usapaypal();
            }
           // Header ('Location: https://www.paypal.com/cgi-bin/webscr');

         
       // }//end captcha validation
    }//total errors
    
} // end if $_POST['submit']

$form->openForm('createUser', '', 'post', 'text');
$form->makeHiddenField('userID', '');

if($_GET['country'] == 'argentina'){
    $form->usselect();
    
}else if($_GET['country'] == 'australia'){
    $form->nzselect();   
    
}else if($_GET['country'] == 'barbados'){
    $form->usselect();
    
}else if($_GET['country'] == 'canada'){
    $form->usselect();
    
}else if($_GET['country'] == 'denmark'){
    $form->euroselect();
    
}else if($_GET['country'] == 'france'){
    $form->euroselect();   
    
}else if($_GET['country'] == 'germany'){
    $form->euroselect();   
    
}else if($_GET['country'] == 'ireland'){
    $form->ukselect();
    
}else if($_GET['country'] == 'italy'){
    $form->euroselect();   
    
}else if($_GET['country'] == 'jamaica'){
    $form->usselect();
    
}else if($_GET['country'] == 'netherlands'){
    $form->euroselect(); 
    
}else if($_GET['country'] == 'newzealand'){
    $form->nzselect();   
    
}else if($_GET['country'] == 'saintvincent'){
    $form->usselect();

}else if($_GET['country'] == 'spain'){
    $form->euroselect();   
    
}else if($_GET['country'] =='sweden'){
    $form->euroselect();   
    
}else if($_GET['country'] == 'switzerland'){
    $form->euroselect();   
    
}else if($_GET['country'] =='trinidadandtobago'){
    $form->usselect();
    
}else if($_GET['country'] == 'unitedkingdom'){
    $form->ukselect();
    
}else if($_GET['country'] == 'unitedstates'){
    $form->usselect();
}
$form->makeInputRow('email', 'checkEmail','Email Address','');
$form->makeInputRow('pwd', 'checkEmpty','Password','password');
$form->makeInputRow('fname', 'checkEmpty','First Name','');
$form->makeInputRow('lname', 'checkEmpty','Last Name','');
$form->makeInputRow('companyname', 'checkEmpty','Company/ Organisation','');
$form->makeInputRow('address', 'checkEmpty','Address','');
$form->makeInputRow('suburb', 'checkEmpty','Suburb','');
$form->makeInputRow('city', 'checkEmpty','Town/ City','');
$form->makeTextRow('country', '','Country','', $country2);
$form->makeInputRow('postcode', '','Postal Code','');
$form->makeInputRow('phone', 'checkNumber','Phone Number','');
$form->makeInputRow('fax', 'checkEmpty','Fax Number','');

//add captcha
//$form->makeCaptcha();
$form->submitButton('Pay Now');
$form->closeForm();



$body = $form->wholeForm;

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<SCRIPT LANGUAGE="JavaScript"><!--
setTimeout('document.paypalform.submit()',1000);
//--></SCRIPT>
</head>

<body>

        
        		<?php
        		echo $body;
?>
                            
</body>
</html>

 

and my form class

 

<?php
/**
* FormClass.php
* creates a form with col1, col2 and col3 for styling
*/

class makeForm extends databaseClass{
    public $wholeForm;                  // all the output ie a complete form
    public $messageArray = array();     // all the messages, initially sent in from the script, but they will be overwritten when data is being validated
    public $valuesArray;                // the filtered values from the $_POST array
    public $clean = array();            // the escaped data, after passing the validation data, ready to use.
    public $totalErrors = 0;            // keeps a count of the errors found during validation

// uses the database class connect method to connect to the database
function __construct($dbConArray){
$this->connect($dbConArray); 
}
    
    ####  HTML writing methods####
    
//opens the form using the typical form. send it the name, acton and method. 
    function openForm($name, $action, $method, $enctype){
$this->wholeForm = '';
        $this->wholeForm .='<form class="form" name="'.$name.'" action="'.$action.'" method="'.$method.'" enctype="'.$enctype.'">';
    }    
    
//makeLable writes the name next to the input field. also adds label for. #col1 for styling
//Needs fieldname and label name.
    function makeLabel($fieldName, $labelName){
$this->wholeForm .= '<label for="'.$fieldName.'" class="col1"  >'.$labelName.' </label>'."\n";
    }
    
//makeMessage makes a message next to the input field ie required. #col3 for styling.
//needs $fieldname
    function makeMessage($fieldName){
$this->wholeForm .=  '<div id="'.$fieldName.'_msg" class="col3">'.$this->messageArray[$fieldName].'</div><div class="clear"></div>'."\n";
    }
    
    
//makeInput creates the input field adding validation and the type of input. #col2 for styling.
//needs $fieldname, $validation -js- and $type 
    function makeInput($fieldName, $validation, $type){
$this->wholeForm .= '<div class="col2"><input class="input" type = "'.$type.'" name="'.$fieldName.'" id="'.$fieldName.'" onblur="'.$validation.'(this.value,\''.$fieldName.'\') " value="'.$this->valuesArray[$fieldName].'"/></div>'."\n";
    }
    
   
//create a text area...send it the fieldname the rows and cols 
    function makeTextarea($fieldName, $validation, $cols, $rows){
        $this->wholeForm .= '<div class="col2"><textarea class="textarea" cols="'.$cols.'" rows="'.$rows.'" name="'.$fieldName.'" onblur="'.$validation.'(this.value,\''.$fieldName.'\')" >'.$this->valuesArray[$fieldName].'</textarea></div>';
    }
    
        function makeTextareaRow($fieldName, $validation, $label, $type, $cols, $rows){
$this->makeLabel($fieldName, $label);
$this->makeTextarea($fieldName, $validation, $cols, $rows);
$this->makeMessage($fieldName);
    }

   function createSelect($fieldName, $validation, $selectArray){
    $this->wholeForm  .= '<div class="col2"><select name="'.$fieldName.'" id="'.$fieldName.'" '.$validation.'>'."\n";
    foreach($selectArray as $key => $value) {
        $this->wholeForm .= '<option ';
        $this->wholeForm  .= 'value="'.$value.'"';
        if($value == $this->valuesArray[$fieldName]){
            $this->wholeForm  .= 'selected="selected"';    
        }
        $this->wholeForm  .= '>';
        $this->wholeForm  .= $key;
        $this->wholeForm  .= '</option>'."\n";
    }
    $this->wholeForm  .= '</select>';
    $this->wholeForm  .= '</div>';
}

//create a select drop down row
    function makeSelectRow($fieldName,$validation, $label, $selectArray){
$this->makeLabel($fieldName, $label);
$this->createSelect($fieldName, $validation, $selectArray);
$this->makeMessage($fieldName);

    }
    
       function createSelect2($fieldName, $validation, $selectArray2){
    $this->wholeForm  .= '<div class="col2"><select name="'.$fieldName.'" id="'.$fieldName.'" '.$validation.'>'."\n";
    foreach($selectArray2 as $key => $value) {
        $this->wholeForm .= '<option ';
        $this->wholeForm  .= 'value="'.$value.'"';
        if($value == $this->valuesArray[$fieldName]){
            $this->wholeForm  .= 'selected="selected"';    
        }
        $this->wholeForm  .= '>';
        $this->wholeForm  .= $key;
        $this->wholeForm  .= '</option>'."\n";
    }
    $this->wholeForm  .= '</select>';
    $this->wholeForm  .= '</div>';
}

//create a select drop down row
    function makeSelectRow2($fieldName,$validation, $label, $selectArray2){
$this->makeLabel($fieldName, $label);
$this->createSelect2($fieldName, $validation, $selectArray2);
$this->makeMessage($fieldName);

    }
    
    
    function createSelect3($fieldName, $validation, $selectArray3){
    $this->wholeForm  .= '<div class="col2"><select name="'.$fieldName.'" id="'.$fieldName.'" '.$validation.'>'."\n";
    foreach($selectArray3 as $key => $value) {
        $this->wholeForm .= '<option ';
        $this->wholeForm  .= 'value="'.$value.'"';
        if($value == $this->valuesArray[$fieldName]){
            $this->wholeForm  .= 'selected="selected"';    
        }
        $this->wholeForm  .= '>';
        $this->wholeForm  .= $key;
        $this->wholeForm  .= '</option>'."\n";
    }
    $this->wholeForm  .= '</select>';
    $this->wholeForm  .= '</div>';
}

//create a select drop down row
    function makeSelectRow3($fieldName,$validation, $label, $selectArray3){
$this->makeLabel($fieldName, $label);
$this->createSelect3($fieldName, $validation, $selectArray3);
$this->makeMessage($fieldName);

    }
    
    function makeCheckbox($class, $country, $countrydisplay, $selected, $checked){
$this->wholeForm .='<input class="'.$class.'" type = "checkbox" Name ="'.$country.'" value ="1" '.$checked.' '.$country.' '.$selected.'>'.$countrydisplay.'<div class="clear"></div>';
    }
    function makeProcessRow($fieldName, $label){
$this->makeLabel($fieldName, $label);
$this->wholeForm .='<select name="accepted" id="accepted">
		    <option value="0">Not Processed</option>
		    <option value="1">Approved</option>
		    <option value="2">Declined</option>
		    </select>';
$this->makeMessage($fieldName);

    }
    
//makeInputRow is called from the script and produces all the components for each row of the form
// needs fieldname, name of validation function, label and type 
    function makeInputRow($fieldName, $validation, $label, $type){
$this->makeLabel($fieldName, $label);
$this->makeInput($fieldName, $validation, $type);
$this->makeMessage($fieldName);

    }
    
    function makeTextRow($fieldName, $validation, $label, $type, $country){
$this->makeLabel($fieldName, $label);
$this->wholeForm.='<div class="col2">'.$country.'</div>';
$this->makeMessage($fieldName);

    }
    
    function submitButton($submitbutton){
$this->wholeForm .= '<input type = "submit" name="submit" value="'.$submitbutton.'" class="submitButton" />';
    }
//closes the form
    function closeForm(){
$this->wholeForm .= '<div class="clear"></div></form>';
    }
    function makeHiddenField($fieldname,$value){
$this->wholeForm .= '<input type="hidden" value="'.$value.'" name = "'.$fieldname.'" />';
    }

//converts the password into sha256 encryption   
function makePassword($fileName){
    $this->clean[$fileName]=hash("sha256",$this->valuesArray[$fileName], false);
}

    /**
     * updateLink makes a form which can be styled to look like a link
     * Used to conceal sensitive data from prying eyes
     * receives script name, field name, value, $label
     */
    
    function formLink($class,$page,$fieldName,$value, $label){
$link = '';
$link .= '<div  class = "linkForm"><form method="post" action="'.$page.'">
<input type="hidden" name="'.$fieldName.'" value="'.$value.'" />
<input class="'.$class.'" type="submit" value="'.$label.'" /></form></div>';
return $link;
    }
    
    //make captcha ###note private key must be generated from recaptcha.net and hard coded in here#### also requires recaptchalib.php
    function makeCaptcha(){
require_once('../includes/recaptchalib.php');
$publickey = "6LfTwwsAAAAAAF-Rpqa2AjXWo9CWfyPIEHvNbrQY"; // get this from the signup page
$privatekey = "6LfTwwsAAAAAAPO_xXInnEd_bOByzcQk0lnB7CZL";// get this from the signup page
$this->wholeForm.='<script type= "text/javascript">

var RecaptchaOptions = {
theme: \'custom\',
lang: \'en\',
custom_theme_widget: \'recaptcha_widget\'
};

</script>
<style type="text/css">
div#recaptcha_image > img{
height:46px;
width:240px;
}
.recaptcha_only_if_image{margin-left:50px;}
.recaptcha_response_field{margin-left:30px;}
</style>

<div id="recaptcha_widget" style="display: none;">
<div class="push"><div id="recaptcha_image"></div></div>
<div class="recaptcha_only_if_incorrect_sol" style="color: red;">Incorrect please try again</div>
<div class="col1"><span class="recaptcha_only_if_image">Enter the words above:</span></div>
<!--<div class="col1"><span class="recaptcha_only_if_audio">Enter the numbers you hear:</span></div>-->
<div class="col2"><input id="recaptcha_response_field" name="recaptcha_response_field" type="text"></div>
<!--<div class="col3"><strong style="font-size: 10px;"><a href="javascript:void(0);">Get another CAPTCHA</a></strong></div>

div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">Get an audio CAPTCHA</a></div><br />
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">Get an image CAPTCHA</a></div><br /><br />
<div><a href="javascript:Recaptcha.showhelp()">Help</a><br />
</div-->

<script type="text/javascript" src="http://api.recaptcha.net/challenge?k='.$publickey.'&lang=en"></script>

<noscript>
<iframe src="http://api.recaptcha.net/noscript?k='.$publickey.'&lang=en" height="200" width="500" frameborder="0"></iframe>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="\'hidden\'" name="\'recaptcha_response_field\'" value="\'manual_challenge\'">
</noscript>

</div><div class="clear"></div>';
    }
    

    #####  End of HTML writing methods #####
    
    #####  Data handling  ######
    
    /**
     * filterEverything
     * use on all incoming $_POST data
     * creates an array of values which will be used when writing the form, if that proves to be necessary.
     */
    
    function filterEverything($data){
foreach($data as $key => $value){
    $this->valuesArray[$key] = htmlspecialchars(trim($value));
} 
    }
    
//stores the values for a sticky form
    function storeValues($data){
foreach($data as $key => $value){
    $this->valuesArray[$key] = trim($value);
}
    }
    
    
//checks whether the input field is empty. If it is a sticky form will appear, requiring the user to fill out the input field.
    function checkUsername($fieldName){
if (strlen($this->valuesArray[$fieldName])==0){				
    $this->totalErrors ++;
    $this->messageArray[$fieldName]= '<span style="color:#CC1100;">*</span>';
}else{
    $test=preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$^", stripslashes($this->valuesArray[$fieldName]));
    if($test==0){
	$this->totalErrors ++;
	$this->messageArray[$fieldName]= '<span style="color:#CC1100;">*</span>';	 
    }else{
	$userquery = "SELECT email FROM tbl_users WHERE email =  '".$this->valuesArray[$fieldName]."'";
	//exit($userquery);
	$this->query($userquery);

	if($this->result->num_rows > 0){
	    $this->totalErrors ++;
	    $this->messageArray[$fieldName]= '<span style="color:#CC1100;">* This email address is taken</span>';    
	}else{
	    $this->messageArray[$fieldName]='';
	    $this->escapeData ($fieldName);
	}
    }
}

    }
    
    function checkNotRequired($fieldName){
if (strlen($this->valuesArray[$fieldName])==0) 	{				
    $this->messageArray[$fieldName]='';
    $this->escapeData ($fieldName);
}else{
    $this->messageArray[$fieldName]='';
    $this->escapeData ($fieldName);
}
    
    } // end notRequired
    
    function checkEmpty($fieldName){
if (strlen($this->valuesArray[$fieldName])==0) 	{				
    $this->totalErrors ++;
    $this->messageArray[$fieldName]= '<span style="color:#CC1100;">*</span>';
}else{
    $this->messageArray[$fieldName]='';
    $this->escapeData ($fieldName);
}
    
    } // end checkEmpty
    
//Validation- checks if the field has only numbers entered. 
    function checkNumber($fieldName){
if(is_numeric($this->valuesArray[$fieldName])){
    $this->messageArray[$fieldName]='';
    $this->escapeData($fieldName);
}else{
    $this->totalErrors ++;
    $this->messageArray[$fieldName]= '<span style=\"color:#CC1100;\">*</span>';
}
    }//checkNumber
    
//checks whether a valid email is entered or not.
    function checkEmail($fieldName){
$test=preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$^", stripslashes($this->valuesArray[$fieldName]));
if($test==0){
    $this->totalErrors ++;
    $this->messageArray[$fieldName]= '<span style=\"color:#CC1100;\">*</span>';	 
} else {
    $this->escapeData ($fieldName);
    $this->messageArray[$fieldName]='';		
}
    }//checkEmail
    
    
    
//checks if the field is empty. If it isnt it calls the checkEmail function to see whether its a valid email or not.
    function rqCheckEmail($fieldName){
    if (strlen($this->valuesArray[$fieldName])==0) {
    $this -> checkEmpty($fieldName);
			    
}else{
    $this -> checkEmail($fieldName);
}
    }//rqCheckEmail
    
    
// final cleanup function. escapedata and strips slashes if necessary.
//run through my_real_escape_string if a database object exists. Send all information to $clean array once complete
    function escapeData ($fieldName){ 
if (ini_get('magic_quotes_gpc')) {
    $this->valuesArray[$fieldName] = stripslashes($this->valuesArray[$fieldName]);
}//escapeData

if(isset($this->mysqli)){
    $this->clean[$fieldName] = mysqli_real_escape_string ($this->mysqli,$this->valuesArray[$fieldName]);
}else{
    $this->clean[$fieldName] = htmlentities($this->valuesArray[$fieldName]); 
}
    } // escapeData
    
######## PAYPAL BUTTONS ############

    //link for europe paypal drop down
    function euroselect (){
    $this->wholeForm .='<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="C5JQGL2B6XLCY">
		<div class="col1"><input type="hidden" name="on0" value="Subscription Level">Subscription Level</div>
		<div class="col2"><select name="os0">
			<option value="Silver">Silver €129.00 EUR</option>
			<option value="Gold">Gold €259.00 EUR</option>
		</select></div>
		<input type="hidden" name="currency_code" value="EUR"><div class="clear"></div>';
    }
    
        //link for great britian paypal drop down
    function ukselect (){
    $this->wholeForm .='<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="DV9JH8V6RF5DJ">
		<div class="col1"><input type="hidden" name="on0" value="Subscription Level">Subscription Level</div>
		<div class="col2"><select name="os0">
			<option value="Silver">Silver £119.00 GBP</option>
			<option value="Gold">Gold £229.00 GBP</option>
		</select></div>
		<input type="hidden" name="currency_code" value="GBP"><div class="clear"></div>';
    }
    
    //link for new zealand paypal drop down
    function nzselect (){
    $this->wholeForm .='<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="ZQ5ZY9QQFRXF6">
		<div class="col1"><input type="hidden" name="on0" value="Subscription Level">Subscription Level</div>
		<div class="col2"><select name="os0">
			<option value="Silver">Silver $249.00 NZD</option>
			<option value="Gold">Gold $489.00 NZD</option>
		</select> 
		</div>
		<input type="hidden" name="currency_code" value="NZD"><div class="clear"></div>';
    }
    
        //link for new zealand paypal drop down
    function usselect (){
    $this->wholeForm .='<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="P4G7G46WET5NG">
		<div class="col1"><input type="hidden" name="on0" value="Subscription Level">Subscription Level</div>
		<div class="col2"><select name="os0">
			<option value="Silver">Silver $179.00 USD</option>
			<option value="Gold">Gold $359.00 USD</option>
		</select></div> 
		<input type="hidden" name="currency_code" value="USD"><div class="clear"></div>';
    }
   
   function usapaypal(){
$this->wholeForm.='<form name="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="P4G7G46WET5NG">
<table>
<tr><td><input type="hidden" name="on0" value="Subscription Level">Subscription Level</td></tr><tr><td><select name="os0">
	<option value="Silver">Silver $179.00</option>
	<option value="Gold">Gold $359.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
';
   }
   
    function europaypal(){
$this->wholeForm.='<form name="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="C5JQGL2B6XLCY">
<table>
<tr><td><input type="hidden" name="on0" value="Subscription Level">Subscription Level</td></tr><tr><td><select name="os0">
	<option value="Silver">Silver €129.00</option>
	<option value="Gold">Gold €259.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>';

   }
   
      function ukpaypal(){
$this->wholeForm.='<form name="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="DV9JH8V6RF5DJ">
<table>
<tr><td><input type="hidden" name="on0" value="Subscription Level">Subscription Level</td></tr><tr><td><select name="os0">
	<option value="Silver">Silver £119.00</option>
	<option value="Gold">Gold £229.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="GBP">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
';
   }
   
      function nzpaypal(){
$this->wholeForm.='<form name="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ZQ5ZY9QQFRXF6">
<table>
<tr><td><input type="hidden" name="on0" value="Subscription Level">Subscription Level</td></tr><tr><td><select name="os0">
	<option value="Silver">Silver $249.00</option>
	<option value="Gold">Gold $489.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="NZD">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
';
   }
}// end class




?>

 

 

It's all a bit over the place at the moment.

Any suggestions would be extremely appreciated. As a last resort I'm just going to make the 'select level' and paypal submit on a seperate page the user is taken to once they have filled out the inital form. then when the administrator approves their account they will have to also select the users level. This however adds an extra field for the user and for the administrator so it is definitely a last resort.

 

:shrug:

Link to comment
Share on other sites

It sounds like you have control over the validation function but not the paypal page.  What you would need to do is build a hidden from in the validation page and create a triger that submits the form if the validation succeeds.  If you have control of the paypal page you can integrate the validation (or just include the functionality) and have the paypal content only loaded on condition of validation success.  Sessions should be created only after validation. 

 

Link to comment
Share on other sites

Ah, so instead of creating the form only if 'if($form->totalErrors == 0)' i run through, storing the variables in the session, the form would always be there but completely hidden and once the form enters if($form->totalErrors == 0){ in the  if $_POST['submit'] section there would be a function to submit the hidden field?

 

I would still need to link the hidden select in the hidden form with the select (silver or gold) that the user has selected.

 

I think I'm just confusing myself more now...

 

 

edit: oops, just noticed i never finished the subject :S

Link to comment
Share on other sites

I just looked at the way I do it and here it is:

 

If (!$totalerror)

include("paypal.php";

 

This way on your validation page, if there are no errors, then that page loads the paypal php file and all the post/get variables are still accessible without create a hidden form.  Please verify that your paypal.php file does not build html formatting (such as <html>,<head>,<body> otherwise these will duplicate).

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.