Jump to content

emilysnothere

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

About emilysnothere

  • Birthday 10/31/1989

Contact Methods

  • Website URL
    http://emily.fox.natcoll.net.nz

Profile Information

  • Gender
    Female
  • Location
    NZ

emilysnothere's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Trying to retun an array which gets a file from a directory and then returns the filename as the key and the complete file url as the value but when returning it it prints out "Array" for each file in the directory rather than the file name: Doing this in wordpress. function wsme_select_css_theme(){ $alt_css_template_path = WSME_THEME_CSS; // Define path to files $alt_widgets_template = array(); // set array $out = ''; // Set var if ( is_dir($alt_css_template_path) ) { // If directory exists if ($alt_css_template_dir = opendir($alt_css_template_path) ) { //opens directory while ( ($alt_css_template_file = readdir($alt_css_template_dir)) !== false ) { //if files are in the directory if(stristr($alt_css_template_file, ".css") !== false) { //if the files are .css files $out[] = array($alt_css_template_file => WSME_THEME_CSS.'/'.$alt_css_template_file); //create the array(filename => file path) for each file in the directory } } } return $out; // return array } } array( 'name' => 'Style', 'id' => WS_THEME_PREFIX . '_style', 'headings' => array( array( 'name' => 'Theme CSS', 'options' => array( array('name' => 'Homepage', 'desc' => ' select the css file of the theme you want for your site', 'id' => WS_THEME_PREFIX . '_theme_css', 'value' => '', 'options' => wsme_select_css_theme(), 'type' => 'select' ) ) ) ) Any suggestions?
  2. Not sure if this is helpful but a script I use to upload and resize images into three folders (original, thumb, large) is <?php class imageValidator{ //assigns $_FILES to short variables //constructor automatically runs when you make a new instance of the class, its a fresh copy. function __construct($files){ $this->origfilename = $files['thePhoto']['name']; $this->tmpName = $files['thePhoto']['tmp_name']; $this->filesize = $files['thePhoto']['size']; $this->fileType = $files['thePhoto']['type']; $this->error = 0; $this->errormess = ''; if(strlen($_POST['alt'])>0){ $this->alt = $_POST['alt']; } } //checks the file size. function checkFileSize(){ //set a max file $maxfilesize = '3000000'; if($this->filesize>$maxfilesize){ $this->error = 1; $this->errormess .= 'Image file is too large.<br />'; } } //checks that it is the correct file extenstion (no docs etc that could break the site) function checkFileExtension(){ //white list of what is allowed $file_types_array=array('jpe','jpg','jpeg','pjpeg','gif','png','JPE','JPG','JPEG','PJPEG','GIF','PNG'); // get the file extension $pos = strpos($this->origfilename,'.'); $extn = substr($this->origfilename,$pos+1); if(!in_array($extn,$file_types_array)){ $this->error = 1; $this->errormess .= 'Incorrect extension<br />'; } } function checkMimeType(){ $file_mime_array = array('image/jpeg','image/pjpeg','image/png','image/gif'); if(!in_array($this->fileType,$file_mime_array)){ $this->error=2; $this->errormess .= 'That is the wrong mime type'; } } //no harmful characters are entered onto the site-file namesthat could break the site function replaceWithUnderscores(){ $this->not = array(' ', '"', '*',',',';',':','{','}','=','+',')','(','&','^','%','$','%23','@','!','`','~','[',']'); $this->filename = str_replace($not,'_', strtolower(trim($this->origfilename))); } function Random_Password($length) { global $string; $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $string = ""; while(strlen($string)<$length) { $pos = rand(1,61); $string .= substr($possible_charactors, $pos,1); } return($string); } //resize image. sent image width/ height from addphoto.php function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile ){ $fw = $forcedwidth; $fh = $forcedheight; $is = getimagesize($sourcefile); if( $is[0] >= $is[1] ){ $orientation = 0; }else{ $orientation = 1; $fw = $forcedheight; $fh = $forcedwidth; } if ( $is[0] > $fw || $is[1] > $fh ){ if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) ){ $iw = $fw; $ih = ( $fw / $is[0] ) * $is[1]; }else{ $ih = $fh; $iw = ( $ih / $is[1] ) * $is[0]; } $t = 1; }else{ $iw = $is[0]; $ih = $is[1]; $t = 2; } if ( $t == 1 ){ $img_src = imagecreatefromjpeg( $sourcefile ); $img_dst = imagecreatetruecolor( $iw, $ih ); imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] ); if( !imagejpeg( $img_dst, $destfile, 90 ) ){ exit( ); } }else if ( $t == 2 ){ copy( $sourcefile, $destfile ); } } //end function resampimagejpg }//end class ?> This form gets sent thePhoto from your form. <?php session_start(); ob_start('gz_handler'); /** *Allows a user to upload a photo then resizes it (calls functions to) putting it in original, thumb and large folders. *This calls functions to check sizes/extensions etc of a file the user has uploaded. *uploads it into the database */ //checks if the user is logged in either by a session or a saved cookie. take them back to login.php if they arent logged in if(!isset($_SESSION['loggedIn'])){ $_SESSION['returnTo']=$_SERVER['SCRIPT_NAME']; header('location: ../index.php'); ob_flush(); } require_once '../../assets/config.php'; require_once '../../assets/DatabaseClass.php'; require_once '../../assets/HtmlClass.php'; require_once '../../assets/FormClass.php'; require_once '../../assets/imageValidator.php';//all this stuff only happens when someone has hit the submit button. if(isset($_SESSION['userID']) && is_numeric($_SESSION['userID'])){ $userID = $_SESSION['userID']; } $form = new makeForm($dbConArray); $form->messageArray['alt'] = '* Required'; $form->messageArray['pDescription'] = '* Required'; $form->messageArray['filename'] = ''; if($_POST['submit']){ //filter data and check it $form->storeValues($_POST); $form->checkEmpty('alt'); $form->checkEmpty('filename'); //check files with imagevalidator - size, extension, names... $files = $_FILES; $check = new imageValidator($files); $check->checkFileSize();//this is checking the file size and if it exceeds it will send an error. $check->checkFileExtension();//checking all acceptable types of file extensions $check->checkMimeType();//checks the Mime type. $check->replaceWithUnderscores();//gets rid of the bad guys and replaces them with underscores //is also giving a nice safe filename. $filename = $check->Random_Password(6).'_'.$check->filename;//creates a new variable which is a combination of random characters and an underscore and our clean filename if($check->error==0){ //upload files to these locations $upload_directory = './images/original/'; $fullname = './images/large/'.$filename; $thumbname = './images/thumb/'.$filename; move_uploaded_file($check->tmpName, $upload_directory.$filename);//moving the file from the temporary folder to the 'original' folder //make new copies the size we want and put in the correct folders according the the size $check->resampimagejpg(600, 450, $upload_directory.$filename, $fullname); $check->resampimagejpg(100, 100, $upload_directory.$filename, $thumbname); $query = "INSERT INTO tbl_photo (filename, alt, pUserID) VALUES ('$filename', '{$form->clean['alt']}', '$userID')"; $a = new databaseClass(); $a->connect($dbConArray); $a->query($query); }//end if($check->error==0) }//end of $_POST. //make the form $form->openForm('addPhoto', '', 'post', 'multipart/form-data'); $form->makeHiddenField('pUserID',$userID); // needed to pass the galleryID back to this page for the update query. $form->makeInputRow('alt', 'checkEmpty','Image Description','text'); $form->makeInputRow('thePhoto', '','Image', 'file'); $form->makeHiddenField('MAX_FILE_SIZE', '2000000'); $form->submitButton('Upload'); $form->closeForm(); ####presentation#### $title = 'Upload and Edit Photos - First Five Years'; $keywork = 'Upload Add Edit Photos First Five Years Baby Online scrapbook'; $description ='Image uploader that allows you to add a photo on your first five years website'; if(isset($check->error)){ if($check->error > 0){ echo $check->errormess; echo '<br / >Unable to upload File.'; }else if($check->error==0){ echo 'OK '.$check->origfilename.' has been renamed '.$filename ; echo '<br />The image has been successfully uploaded.'; } } $b = new makeForm($dbConArray); //connect to the database $displayquery= "SELECT photoID, filename FROM tbl_photo WHERE pUserID = $userID ORDER BY photoID DESC"; $b->query($displayquery); // the query method runs the query and returns $a->result; $output = ''; // somewhere to store all the output as we process it and format it $output = '<table class="imageform" >'; while($row = $b->result->fetch_array(MYSQLI_BOTH)){ $output .= '<tr>'; $output .=' <td><img src="images/thumb/'.$row['filename'].'" /></td>'; $output .= '<td>'; $output .= $b->formLink('linkdelete','deletephoto.php','photoID', $row['photoID'],''); $output .= '</td>'; $output .= '</tr>'."\n"; } $output .= '</table>'; #####CONTENT $heading ='ADD/ EDIT PHOTOS'; $body = ''; $body .= $form->wholeForm; $body .= $output; include ('assets/head.php'); ob_flush(); ?> Of course this is my script so it also requires my form class to write the form and other includes from the website etc plus the database...but hopefully you can incoporate the 'imageValidator.php script and the following code to your page: //check files with imagevalidator - size, extension, names... $files = $_FILES; $check = new imageValidator($files); $check->checkFileSize();//this is checking the file size and if it exceeds it will send an error. $check->checkFileExtension();//checking all acceptable types of file extensions $check->checkMimeType();//checks the Mime type. $check->replaceWithUnderscores();//gets rid of the bad guys and replaces them with underscores //is also giving a nice safe filename. $filename = $check->Random_Password(6).'_'.$check->filename;//creates a new variable which is a combination of random characters and an underscore and our clean filename if($check->error==0){ //upload files to these locations $upload_directory = './images/original/'; $fullname = './images/large/'.$filename; $thumbname = './images/thumb/'.$filename; move_uploaded_file($check->tmpName, $upload_directory.$filename);//moving the file from the temporary folder to the 'original' folder //make new copies the size we want and put in the correct folders according the the size $check->resampimagejpg(600, 450, $upload_directory.$filename, $fullname); $check->resampimagejpg(100, 100, $upload_directory.$filename, $thumbname); Let me know if this helps
  3. I have fixed the issue For future reference (if anyone else is silly enough to make this mistake ) the issue was as follows: the form that was not working opened with: $form->openForm('domainForm', '', 'post', 'text'); The form that worked opened with: $form->openForm('domainForm', '', 'post', ''); or $form->openForm('addphone', '', 'post', 'multipart/form-data'); The form enctype was being set to 'text' and chrome had an issue with this Thanks, Emily
  4. Sorry, I got sidetracked writing that... The issue is that some forms, once the submit button is selected, just refresh the page without storing data or returning errors if there are any (or sending the form). (essentially the submit function is not being picked up but instead the page is just refreshed) However, this doesnt happen with login forms or with, as shown in the above example, all my forms which are written with the same form class.
  5. I am having an issue with forms submitting on Chrome and Safari. I initially thought this was a $_POST issue, after doing some googling, however I can still use my logins (which use $_POST) and then realized some of my forms do work! An example of a form that does work is : <?php require_once 'includes/headcode.php'; $form = new makeForm($dbConArray); $form->messageArray['customername'] = '*'; $form->messageArray['address'] = '*'; $form->messageArray['suburb'] = '*'; $form->messageArray['city'] = '*'; $form->messageArray['state'] = '*'; $form->messageArray['phone'] = '*'; $form->messageArray['planone'] = 'Total $22 Each'; $form->messageArray['plantwo'] = 'Total $61 Each'; $formsent = 0; //Process the form if($_POST['submit']){ // a) store data $form->storeValues($_POST); // b) Check each one, $form->checkEmpty('customername'); $form->checkEmpty('address'); $form->checkEmpty('suburb'); $form->checkEmpty('city'); $form->checkEmpty('state'); $form->checkEmpty('phone'); $form->checkNotRequired('mobile'); $form->checkNotRequired('ccard'); $form->checkNotRequired('ctype'); $form->checkNotRequired('cexpiry'); $form->checkNotRequired('business'); $form->checkNotRequired('abnno'); $form->checkNotRequired('planone'); $form->checkNotRequired('plantwo'); $form->checkNotRequired('numberreq'); $form->checkNotRequired('porting'); $form->checkNotRequired('dob'); $form->checkNotRequired('currentcarrier'); $form->checkNotRequired('currentaccount'); $form->checkNotRequired('websiteint'); $form->checkNotRequired('itint'); $form->checkNotRequired('comments'); //filter the message or enquiry, stripping < and > from it to prevent injections. Not as important here as it only sends an email. $filterMessage = array('<', '>'); $messageCleaner = str_replace($filterMessage,"", $_REQUEST['comments']); // Check for errors if($form->totalErrors == 0){ //c) insert cleaned form details into database. $query= "INSERT INTO tbl_phone SET customername = '{$form->clean['customername']}', address = '{$form->clean['address']}', suburb = '{$form->clean['suburb']}', city = '{$form->clean['city']}', state = '{$form->clean['state']}', phone = '{$form->clean['phone']}', mobile = '{$form->clean['mobile']}', ccard = '{$form->clean['ccard']}', ctype = '{$form->clean['ctype']}', cexpiry= '{$form->clean['cexpiry']}', business= '{$form->clean['business']}', abnno= '{$form->clean['abnno']}', planone= '{$form->clean['planone']}', plantwo= '{$form->clean['plantwo']}', numberreq= '{$form->clean['numberreq']}', porting= '{$form->clean['porting']}', dob= '{$form->clean['dob']}', currentcarrier= '{$form->clean['currentcarrier']}', currentaccount= '{$form->clean['currentaccount']}', websiteint= '{$form->clean['websiteint']}', itint= '{$form->clean['itint']}', callcenter= '$callcenter', comments = '{$form->clean['comments']}'"; $form->query($query); //d) send form details to the designated person. //email form if there are no errors in it // message that will be inserted into the mail $message =''; $message .='A new phone plan service form has been completed <br />'; $message .='<p>Call Center Staff Member Details:<br /> '.$callcenter.'</p>'; $message .='<br />Customer Details'; $message .= '<table>'; $message .= '<tr><td>Customer Name: </td><td>'. $form->clean['customername']. "\r\n" ; $message .= '</td></tr><tr><td>Address: </td><td>'. $form->clean['address']. "\r\n" ; $message .= '</td></tr><tr><td>Suburb: </td><td>'.$form->clean['suburb']. "\r\n" ; $message .= '</td></tr><tr><td>Town/ City: </td><td>'.$form->clean['city']. "\r\n" ; $message .= '</td></tr><tr><td>State: </td><td>'.$form->clean['state']. "\r\n" ; $message .= '</td></tr><tr><td>Contact Phone Number: </td><td>'.$form->clean['phone']. "\r\n" ; $message .= '</td></tr><tr><td>Mobile number: </td><td>'.$form->clean['mobile']. "\r\n" ; $message .='</td></tr></table>'; $message .='<br />Card Details'; $message .= '<table>'; $message .= '<tr><td>Credit Card Number: </td><td>'.$form->clean['ccard']. "\r\n" ; $message .= '</td></tr><tr><td>Card type: </td><td>'.$form->clean['ctype']. "\r\n" ; $message .= '</td></tr><tr><td>Expiry Date: </td><td>'.$form->clean['cexpiry']. "\r\n" ; $message .='</td></tr></table>'; $message .='<br />Business Details'; $message .= '<table>'; $message .= '<tr><td>Business Name: </td><td>'.$form->clean['business']. "\r\n" ; $message .= '</td></tr><tr><td>ABN Number: </td><td>'.$form->clean['abnno']. "\r\n" ; $message .='</td></tr></table>'; $message .='<br />Plan Details'; $message .= '<table>'; $message .= '<tr><td>Handsets for Mobile $22Simply Business Mobile Plan: </td><td>'.$form->clean['planone']. "\r\n" ; $message .= '</td></tr><tr><td>Handsets for Blackberry $22 Simply Business Mobile plan - Plus $39 Unlimited Data: </td><td>'.$form->clean['plantwo']. "\r\n" ; $message .= '</td></tr><tr><td>New number required? </td><td>'.$form->clean['numberreq']. "\r\n" ; $message .= '</td></tr><tr><td>Porting Number: </td><td>'.$form->clean['porting']. "\r\n" ; $message .= '</td></tr><tr><td>Current Carrier: </td><td>'.$form->clean['currentcarrier']. "\r\n" ; $message .= '</td></tr><tr><td>Current Account Number with Carrier: </td><td>'.$form->clean['currentaccount']. "\r\n" ; $message .= '</td></tr><tr><td>Message: </td><td>'.stripslashes(nl2br($messageCleaner)). "\r\n" ; $message .='</td></tr></table>'; $message .='<br />Extras'; $message .= '<table>'; $message .= '<tr><td>Website Interest: </td><td>'.$form->clean['websiteint']. "\r\n" ; $message .= '</td></tr><tr><td>IT Interest: </td><td>'.$form->clean['itint']. "\r\n" ; $message .='</td></tr></table>'; $mail = new PHPMailer(); $body = $mail->getFile('phone.php'); $body = eregi_replace("[\]",'',$message); $subject = eregi_replace("[\]",'',$subject); $mail->From = $form->clean['email']; $mail->FromName = "FROMNAME"; $mail->Subject = "Call Center - Phone Service"; $mail->MsgHTML($message); //email address the message is being sent to. $mail->AddAddress("EMAIL@gmail.com", "FROMNAME"); if($mail->Send()) { // We'll be outputting a PDF $formsent = 1; $sentMessage= '<p>The form has been sent successfully.</p>'; } }else{ $formError = '<div class="error">Please fill in the required fields</div>'; } //e) return call center user to the admin index page. //header('Location: viewnewsletters.php'); ob_flush(); } // end if $_POST['submit'] $selectArray = array ('Visa' => 'Visa', 'Master Card'=>'Master Card', 'American Express'=>'American Express'); $form->openForm('addphone', '', 'post', 'multipart/form-data'); $form->makeHiddenField('phoneID',$phoneID); $form->createHeading('Customer Details'); $form->makeInputRow('customername', 'checkEmpty','Name','','text'); $form->makeInputRow('address', 'checkEmpty','Address','','text'); $form->makeInputRow('suburb', 'checkEmpty','Suburb','','text'); $form->makeInputRow('city', 'checkEmpty','City','','text'); $form->makeInputRow('state', 'checkEmpty','State','','text'); $form->makeInputRow('phone', 'checkEmpty','Contact Number','','text'); $form->makeInputRow('mobile', '','Mobile Number','','text'); $form->createHeading('Credit Card Details'); $form->makeInputRow('ccard', 'checkEmpty','Card Number','','text'); $form->makeSelectRow('ctype', 'checkEmpty','Card Type',$selectArray); $form->makeInputRow('cexpiry', 'checkEmpty','Card Expiry','mm/yyyy','text'); $form->createHeading('formtext', 'Business details'); $form->makeInputRow('business', 'checkEmpty','Business Name','','text'); $form->makeInputRow('abnno', 'checkEmpty','ABN Number','','text'); $form->createHeading('Plan Details'); $form->makeText('indentformtext', 'Number of Handsets'); $form->makeInputRow('planone', '','Mobile $22 Simply Business Mobile plan','','text'); $form->makeInputRow('plantwo', '','Blackberry $22 Simply Business Mobile plan - Plus $39 Unlimited Data Pack','','text'); $form->createHeading('Other Information'); $form->makeInputRow('numberreq', 'checkEmpty','New Number Required? ','','text'); $form->makeInputRow('porting', 'checkEmpty','Porting Number','','text'); $form->makeInputRow('dob', 'checkEmpty','Date of Birth','','text'); $form->makeInputRow('currentcarrier', 'checkEmpty','Current Carrier','','text'); $form->makeInputRow('currentaccount', 'checkEmpty','Current Account Number with Carrier','','text'); $form->makeTextareaRow('comments', '', 'Extra Comments', '', '25', '5'); $form->createHeading('Extras'); $form->makeInputRow('websiteint', '','Website Interest','','text'); $form->makeInputRow('itint', '','IT Interest','','text'); $form->submitButton('Submit'); $form->closeForm(); ###### Content inserted into template ###### $heading = 'Add Customer Phone Plan'; $body = ''; if($formsent != 1){ $body .= $form->wholeForm; }else{ $body .= $formConfirmation; } ###### Include Template ##### include 'template.php'; ob_flush(); // because we started it at the top of the script ?> and one that doesnt work <?php require_once 'includes/headcode.php'; $sentMessage ='Please Fill out the form'; //create the form $form = new makeForm($dbConArray); $formsent=0; // default messages for registrant details $form->messageArray['domainName'] = '*'; $form->messageArray['abn'] = '*'; $form->messageArray['term'] = '* 2 year min for Australian domains'; $form->messageArray['registrantName'] = '* The person or company that <br />this domain will be registered to'; $form->messageArray['address1'] = '*'; $form->messageArray['city'] = '*'; $form->messageArray['country'] = '*'; $form->messageArray['phone'] = '*'; $form->messageArray['email'] = '*'; // default messages for administrative details $form->messageArray['adminContactName'] = '* The person or company that <br />will administer this domain'; $form->messageArray['adminAddress1'] = '*'; $form->messageArray['adminCity'] = '*'; $form->messageArray['adminCountry'] = '*'; $form->messageArray['adminPhone'] = '*'; $form->messageArray['adminEmail'] = '*'; if($_POST['submit']){ // the test to see if the form has been submitted then process data. // filter all the data $form->filterEverything($_POST); //Check all the fields for registrant using php to make sure they're filled in correctly $form->checkEmpty('domainName'); $form->checkNotRequired('abn'); $form->checkNotRequired('term'); $form->checkNotRequired('hostingPackage'); $form->checkNotRequired('designPackage'); $form->checkEmpty('registrantName'); $form->checkEmpty('address1'); $form->checkNotRequired('address2'); $form->checkEmpty('city'); $form->checkNotRequired('postcode'); $form->checkNotRequired('state'); $form->checkNotRequired('country'); $form->checkEmpty('phone'); $form->checkNotRequired('fax'); $form->rqCheckEmail('email'); //Check all the fields for the administrative contact using php to make sure they're filled in correctly $form->checkEmpty('adminContactName'); $form->checkEmpty('adminAddress1'); $form->checkNotRequired('adminAddress2'); $form->checkEmpty('adminCity'); $form->checkNotRequired('adminPostcode'); $form->checkNotRequired('adminState'); $form->checkNotRequired('adminCountry'); $form->checkEmpty('adminPhone'); $form->checkNotRequired('adminFax'); $form->rqCheckEmail('adminEmail'); // Check for errors if($form->totalErrors == 0){ //email form using php mailer if there are no errors in it // message - registrant details $message = '<b>Domain Name:</b> '. $form->clean['domainName']. "\r\n" ; $message .= '<p><b>DOMAIN REGISTRATION </b>'; $message .= '<br /><b>ABN or ACN Number: </b>'. $form->clean['abn']. "\r\n" ; $message .= '<br /><b>Term: </b>'. $form->clean['term']. "\r\n" ; $message .= '</p><p><b>HOSTING</b>'; $message .= '<br /><b>Hosting Package: </b>'. $form->clean['hostingPackage']. "\r\n" ; $message .= '</p><p><b>DESIGN</b>'; $message .= '<br /><b>Design Package: </b>'. $form->clean['designPackage']. "\r\n" ; $message .= '</p><p><b>REGISTRANT DETAILS </b>'; $message .= '<br /><b>Registrant Name:</b> '. $form->clean['registrantName']. "\r\n" ; $message .= '<br /><b>Address 1:</b> '. $form->clean['address1']. "\r\n" ; $message .= '<br /><b>Address 2: </b>'. $form->clean['address2']. "\r\n" ; $message .= '<br /><b>City: </b>'. $form->clean['city']. "\r\n" ; $message .= '<br /><b>Post Code: </b>'. $form->clean['postcode']. "\r\n" ; $message .= '<br /><b>State: </b>'. $form->clean['state']. "\r\n" ; $message .= '<br /><b>Country:</b> '. $form->clean['country']. "\r\n" ; $message .= '<br /><b>Phone: </b>'. $form->clean['phone']. "\r\n" ; $message .= '<br /><b>Fax: </b>'. $form->clean['fax']. "\r\n" ; $message .= '<br /><b>Email:</b> '. $form->clean['email']. "\r\n" ; // message - administrative details $message .= '</p><p><b>ADMINISTRATIVE DETAILS </b>'; $message .= '<br /><b>Administrative Contact Details: </b>'. $form->clean['adminContactName']. "\r\n" ; $message .= '<br /><b>Address 1: </b>'. $form->clean['adminAddress1']. "\r\n" ; $message .= '<br /><b>Address 2: </b>'. $form->clean['adminAddress2']. "\r\n" ; $message .= '<br /><b>City: </b>'. $form->clean['adminCity']. "\r\n" ; $message .= '<br /><b>Post Code: </b>'. $form->clean['adminPostcode']. "\r\n" ; $message .= '<br /><b>State: </b>'. $form->clean['adminState']. "\r\n" ; $message .= '<br /><b>Country:</b> '. $form->clean['adminCountry']. "\r\n" ; $message .= '<br /><b>Phone:</b> '. $form->clean['adminPhone']. "\r\n" ; $message .= '<br /><b>Fax:</b> '. $form->clean['adminFax']. "\r\n" ; $message .= '<br /><b>Email:</b> '. $form->clean['adminEmail']. "\r\n" ; $message .= '</p>' ; $mail = new PHPMailer(); $body = $mail->getFile('website.php'); $body = eregi_replace("[\]",'',$message); $subject = eregi_replace("[\]",'',$subject); $mail->From = $form->clean['email']; $mail->FromName = "FROMNAME"; $mail->Subject = "Call Center Website Lead"; $mail->MsgHTML($message); //email address it is being sent to $mail->AddAddress("EMAIL@gmail.com", "FROMNAME"); if($mail->Send()) { $formsent = 1; $sentMessage = '<p>The form has been sent successfully.</p>'; } else { $sentMessage = '<div class="contact_text">Sorry, the request could not be processed.</div>'; } }else{ $sentMessage='<p class="error">Please fill in the required fields</p><br />'; } // end $form->totalErrors } // end if $_POST['submit'] $selectArray = array ('6 Months'=>'6 Months', '1 Year'=>'1 Year', '2 Years'=>'2 Years', '5 Years'=>'5 Years', '10 Years'=>'10 Years'); $selectArray3 = array ('Victoria'=>'Victoria', 'New South Wales'=>'New South Wales', 'Queensland'=>'Queensland', 'Tasmania'=>'Tasmania', 'South Australia'=>'South Australia', 'Northern Territory'=>'Northern Territory', 'Western Australia'=>'Western Australia'); $selectArray2 = array ('Australia'=>'Australia'); #### WRITE THE FORM #### $form->openForm('domainForm', '', 'post', 'text'); //registrant $form->createHeading('Website Services'); $form->makeInputRow('domainName', 'checkEmpty','Domain Name', 'text'); $form->createHeading('Domain Registration'); $form->makeInputRow('abn', 'checkEmpty','ABN or ACN Number', 'text'); $form->makeSelectRow('term', 'checkEmpty','Term' ,$selectArray ); $form->createHeading('Hosting'); $form->makeCheckBoxRow('hostingPackage','Webhosting Package'); $form->createHeading('Web Design'); $form->makeCheckBoxRow_design('designPackage','Design Package'); $form->createHeading('Registrant Details'); $form->makeInputRow('registrantName', 'checkEmpty','Registrant Name', 'text'); $form->makeInputRow('address1', 'checkEmpty','Address 1', 'text'); $form->makeInputRow('address2', '','Address 2', 'text'); $form->makeInputRow('city', 'checkEmpty','City', 'text'); $form->makeInputRow('postcode', '','Post Code', 'text'); $form->makeSelectRow('state', 'checkEmpty','State', $selectArray3); $form->makeSelectRow('country', 'checkEmpty','Country', $selectArray2); $form->makeInputRow('phone', 'checkNumber','Phone', 'text'); $form->makeInputRow('fax', '','Fax', 'text'); $form->makeInputRow('email', 'checkEmail','Email', 'text'); //checkbox that will copy the registrant information to the administrative information if checked. $form->makeCopyCheckbox(); //administrative $form->createHeading('Administrative Contact Details'); $form->makeInputRow('adminContactName', 'checkEmpty','Administrative Contact Name', 'text'); $form->makeInputRow('adminAddress1', 'checkEmpty','Address 1', 'text'); $form->makeInputRow('adminAddress2', '','Address 2', 'text'); $form->makeInputRow('adminCity', 'checkEmpty','City', 'text'); $form->makeInputRow('adminPostcode', '','Post Code', 'text'); $form->makeSelectRow('adminState', 'checkEmpty','State', $selectArray3); $form->makeSelectRow('adminCountry', 'checkEmpty','Country', $selectArray2); $form->makeInputRow('adminPhone', 'checkNumber','Phone', 'text'); $form->makeInputRow('adminFax', '','Fax', 'text'); $form->makeInputRow('adminEmail', 'checkEmail','Email', 'text'); $form->submitButton('Submit'); $form->closeForm(); ###### Content inserted into template ###### $heading = 'Add Web Services'; $body = ''; if($formsent !=1){ $body .= $form->wholeForm; }else{ $body .= $formConfirmation; } ###### Include Template ##### include 'template.php'; ob_flush(); // because we started it at the top of the script ?> Both these scripts use the same form/database/headcode/config scripts. Also, I know the fields are slightly different, however I'm having this issue with contact forms that just contain basic fields used in both forms. Does anyone know where I went wrong?
  6. 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
  7. 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.
  8. Hey this is where $fieldName is being set $selectArray = array ('6 Months'=>'6 Months', '1 Year'=>'1 Year', '2 Years'=>'2 Years', '5 Years'=>'5 Years', '10 Years'=>'10 Years'); #### WRITE THE FORM #### $form->openForm('domainForm', '', 'post', 'text'); //registrant $form->makeInputRow('domainName', 'checkEmpty','Domain Name', 'text'); // drop down example $form->makeSelectRow('terms', 'checkEmpty','Term',$selectArray); $form->createHeading('Registrant Details'); $form->makeInputRow('registrantName', 'checkEmpty','Registrant Name', 'text'); $form->makeInputRow('address1', 'checkEmpty','Address 1', 'text'); $form->makeInputRow('address2', '','Address 2', 'text'); $form->makeInputRow('city', 'checkEmpty','City', 'text'); $form->makeInputRow('postcode', '','Post Code', 'text'); $form->makeInputRow('province', '','Province', 'text'); //drop down example two $form->makeCountryRow('country', '', 'Country', ''); $form->submitButton('Submit'); $form->closeForm(); ?> and heres the source code i receive <form class="form" name="domainForm" action="" method="post" enctype="text"> <label for="domainName" class="col1" >Domain Name : </label> <div class="col2"><input class="input" type = "text" name="domainName" id="domainName" onblur="checkEmpty(this.value,'domainName') " value=""/></div> <div id="domainName_msg" class="col3">*</div><div class="clear"></div> <label for="terms" class="col1" >Term : </label> <div class="col2"><select name="terms" id="terms" checkEmpty> <option value="6 Months">6 Months</option> <option value="1 Year">1 Year</option> <option value="2 Years">2 Years</option> <option value="5 Years">5 Years</option> <option value="10 Years">10 Years</option> </select></div><div id="terms_msg" class="col3"></div><div class="clear"></div> <span class="formHeading">Registrant Details</span><div class="clear"></div><label for="registrantName" class="col1" >Registrant Name : </label> <div class="col2"><input class="input" type = "text" name="registrantName" id="registrantName" onblur="checkEmpty(this.value,'registrantName') " value=""/></div> <div id="registrantName_msg" class="col3">* The person or company that this domain will be registered to</div><div class="clear"></div> <label for="address1" class="col1" >Address 1 : </label> <div class="col2"><input class="input" type = "text" name="address1" id="address1" onblur="checkEmpty(this.value,'address1') " value=""/></div> <div id="address1_msg" class="col3">*</div><div class="clear"></div> <label for="address2" class="col1" >Address 2 : </label> <div class="col2"><input class="input" type = "text" name="address2" id="address2" onblur="(this.value,'address2') " value=""/></div> <div id="address2_msg" class="col3"></div><div class="clear"></div> <label for="city" class="col1" >City : </label> <div class="col2"><input class="input" type = "text" name="city" id="city" onblur="checkEmpty(this.value,'city') " value=""/></div> <div id="city_msg" class="col3">*</div><div class="clear"></div> <label for="postcode" class="col1" >Post Code : </label> <div class="col2"><input class="input" type = "text" name="postcode" id="postcode" onblur="(this.value,'postcode') " value=""/></div> <div id="postcode_msg" class="col3"></div><div class="clear"></div> <label for="province" class="col1" >Province : </label> <div class="col2"><input class="input" type = "text" name="province" id="province" onblur="(this.value,'province') " value=""/></div> <div id="province_msg" class="col3"></div><div class="clear"></div> <label for="country" class="col1" >Country : </label> <div class="col2"> <select name="country" id="country"> <option value="NZ" selected>New Zealand</option> <option value="AF">Afghanistan</option> </select> <div class="clear"></div><input type = "submit" name="submit" value="Submit" class="submitButton" /><div class="clear"></div></form>
  9. I have created a form using my FormClass.php however once submitted it emails me all the values except those that are from a drop down select or radio box. Theres probably a quick fix to this so if anyone has any ideas please help me here are some examples of my code: Drop down menu: //list of all countries displayed in a drop down select function selectCountry($fieldName){ $this->wholeForm .='<div class="col2"> <select name="'.$fieldName.'" id="'.$fieldName.'"> <option value="NZ" selected>New Zealand</option> <option value="AF">Afghanistan</option> </select>'; } An input field thats values are being picked up by the php mailer 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"; } the php mailer code // message - registrant details $message = 'Domain Name: '. $form->clean['domainName']. "\r\n" ; $message .= '<br />Term:'. $form->clean['term']. "\r\n" ; $message .= '<p>REGISTRANT DETAILS '; $message .= '<br />Registrant Name: '. $form->clean['registrantName']. "\r\n" ; $message .= '<br />Address 1: '. $form->clean['address1']. "\r\n" ; $message .= '<br />Address 2: '. $form->clean['address2']. "\r\n" ; $message .= '<br />City: '. $form->clean['city']. "\r\n" ; $message .= '<br />Post Code: '. $form->clean['postcode']. "\r\n" ; $message .= '<br />Province: '. $form->clean['province']. "\r\n" ; $message .= '<br />Country: '. $form->clean['country']. "\r\n" ; $message .= '<br />Phone: '. $form->clean['phone']. "\r\n" ; $message .= '<br />Fax: '. $form->clean['fax']. "\r\n" ; $message .= '<br />Email: '. $form->clean['email']. "\r\n" ; $mail = new PHPMailer(); $body = $mail->getFile('contact.php'); $body = eregi_replace("[\]",'',$message); $subject = eregi_replace("[\]",'',$subject); $mail->From = $form->clean['email']; $mail->FromName = "__________"; $mail->Subject = "Enquiry"; $mail->MsgHTML($message); //email address it is being sent to $mail->AddAddress("_______@gmail.com", "_______"); As well as the drop down select, values from a radio check box are also not being picked up Any suggestions?
  10. Thanks for the help I fixed it by putting the query etc in my formClass function checkUsername($fieldName){ if (strlen($this->valuesArray[$fieldName])==0){ $this->totalErrors ++; $this->messageArray[$fieldName]= 'This field cannot be empty'; }else{ $userquery = "SELECT username FROM tbl_user WHERE username = '".$this->valuesArray[$fieldName]."'"; //exit($userquery); $this->query($userquery); if($this->result->num_rows > 0){ $this->totalErrors ++; $this->messageArray[$fieldName]= 'Sorry, username already exists.'; }else{ $this->messageArray[$fieldName]='Good'; $this->escapeData ($fieldName); } } } so its all in one place just called by $form->checkUsername('username'); (for people trying this in the future I guess...)
  11. oh okay, I've changed that too thanks Still getting the mysql_num_rows error though
  12. Hey, my function is function query($query){ $this->result = @$this->mysqli->query($query) or die ($query.'<br />'. $mysqli->error.'<br />'. __FILE__.__LINE__.__FUNCTION__); } I tried your suggestion, but I'm still getting the error (I guess because that isnt really the same function) Oh well hopefully I can get some help in class today as well
  13. Please help me, I'm trying to check whether the username already exists but I keep getting the error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in" and I have no idea why. Here is my php code. The fieldname (username) and $number (of rows) get sent through to a formClass. 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 the username doesnt exist $userquery = "SELECT username FROM tbl_user WHERE username = '{$_POST['username']}'"; $form->query($userquery); $number = mysql_num_rows($form); // b) Check each field $form->checkUsername('username', $number); $form->checkEmpty('firstname'); $form->checkEmpty('lastname'); .....etc Here's what happens in the formClass //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, $number){ //checks if the field has been filled out correctly if (strlen($this->valuesArray[$fieldName])==0){ $this->totalErrors ++; $this->messageArray[$fieldName]= 'This field cannot be empty'; //checks if more than one of the usernames exist }else if($number > 0){ $this->messageArray[$fieldName]= 'Sorry, username already exists.'; }else{ $this->messageArray[$fieldName]='Good'; $this->escapeData ($fieldName); } } So yeah, I'm stumped, though its probably something obvious. Also if anyone has any suggestions of a better way to do this please share.
×
×
  • 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.