Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 31st, 2003, 11:02 AM
carlmty carlmty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 carlmty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Web form using php to import into Access db

Hi everyone:

I need to make a web form in php, that sends me the results by mail, ok, that is the easy part, I know how to do it, the thing I don't know, is that I need that the results get formated to import them into Access, as a delimited text with | delimiter.

I already have the web form, but the results that send by mail are not formatted to import them into Access, here is an example what I need, to ilustrate my question better:

Web form: (What the user see and must fill)

Name: John
Last name: Doe
Sec last name: Doyle
Gender: 0 (Where 0 is Male and 1 is Female)
Marital status: 1 (Where 0 is Single, 1 is Married, 2 is divorced, etc)

This is what I get by mail, instead of that, what I need to have is this:

(Table definitions for Access)

*name|last|sec|gender|marital*

But with the user info in it, like this:
*John|Doe|Doyle|0|1*

And once I have this message in my mail, I can copy, paste it in text, save it into one file, and then, go to Access and import the file.

Also, because is a convention of the application made it by Access (I didn't develop that application) I need to include the * asterisk at the beginning and end of web form, just to keep things in order, and not mixup them.

The questions are:
1.- How can I convert or transform automatically the mail message to have it ready when arrives to my mail, in order just to copy, paste and import into Access?

2.- How can I include the * asterisk at the beginning and the end of each web form is send by users?

Thanks in advance.

Reply With Quote
  #2  
Old August 1st, 2003, 11:42 AM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 57 sec
Reputation Power: 12
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
How are you doing your mailing? With the PHP mail function or by using just a normal html form with it's action as a mailto?
Can you post some code so that we can get a better understanding of how you're approaching this?

-b
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
  #3  
Old August 1st, 2003, 04:58 PM
carlmty carlmty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 carlmty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is how I did it and also a question...

Hi bcyde:

I just made a php file, named mailme.php, and put this code in it:

PHP Code:
<?php
if (mail("someuser@somedomain.com""Place a message here""*$name|$lastname|$seclname|$gender|$marital*"))
include 
'redirect-success-file.php';
else 
   include 
'redirect-error-file.php';
?>


In my form, I called this script from <form action='mailme.php' method='POST'>

Now the problem I have is that I need to validate the form, because in my case all the fields are mandatory.

I already tried with a validation Javascript, but it didn't work for radial buttons and drop down menus, just for text.

Also I have a form-validator.php class, but I dont know how to include it and configure it to fit my needs.

Here is the code:

PHP Code:
<?php 
#  ==================================================
================= 

# iMarc PHP Library 
# Copyright 2002, iMarc, LLC 

# @version: 1.4 
# @last_update: 2003-01-01 
# @description: Form Validation Functions 

# @changes: v1.4 - Added isset() when validating (compatibale with PHP error notices) 

#  ==================================================
================= 
/* 
    METHODS: 
        validate_fields()     - Validates a comma-separated string of $required_fields 
        create_error()     - Private class function to handle errors 
*/ 
# ------------------------------------------------------------------- # 
# VALIDATOR CLASS 
# ------------------------------------------------------------------- # 
class validator 
    var 
$error$error_message;        // (string) HTML formatted error message 
    
var $error_array = array();        // (array)    Error 

    # ----------------------------------- # 
    # FUNCTION:     validate_fields 
    # DESCRIPTION:     Validates a comma-separated string of $required_fields 
    # 
    # ARGS:         $required_fields    (string) comma separated string of required form field names 
    # 
    # RETURNS:        TRUE if all form fields are not NULL, FALSE if at least one fields is NULL. 
    # ----------------------------------- # 
    
function validate_fields($required_fields='') { 
        if (!
$required_fields) { 
            return 
true
        } 
        
$__errors = array(); 

        
// Delete all spaces from the field names and place the them in an array. 
        
$__fields explode (","str_replace(" """$required_fields)); 
        foreach (
$__fields as $__current_field) {     
            if (
trim($__current_field)) { 
                if (
strstr($__current_field"||")) { 
     
                    
/* * * *  "OR" fields * * * */ 
                     
                    // this_field||that_field - double pipe separated field names will check <this_field> or <that_field> 
                    
$__error      false
                    
$__no_error   false
                    
$__sub_fields explode("||"$__current_field); 
         
                    foreach (
$__sub_fields as $__current_sub_field) { 
                        
$__current_sub_field trim($__current_sub_field); 
                         
                        
settype($_REQUEST[$__current_sub_field], "string"); 
                         
                        if (!
$__no_error && isset($_REQUEST[$__current_sub_field]) && !strlen(trim($_REQUEST[$__current_sub_field]))) { 
                            
$__error      true
                        } else { 
                            
$__no_error   1
                            
$__error      false
                        } 
                    } 

                    if (
$__error) { 
                        
$__errors[] = $__current_field
                    } 
                } else { 
                     
                    
/* * * *  Regular fields * * * */ 
                     
                    // This separates regular single fields and makes them global variables 
                    
$__current_field trim($__current_field);                 
                    
settype($_REQUEST[$__current_field], "string"); 

                    if (isset(
$_REQUEST[$__current_field]) && !strlen(trim($_REQUEST[$__current_field]))) { 
                        
$__errors[] = $__current_field
                    } 
                } 
            } 
        } 
         
        if (
count($__errors)) { 
            
$this->create_error($__errors"validate_fields"); 
            return 
FALSE
        } else { 
            return 
TRUE
        } 
    } 

/* Private */ 
    # ----------------------------------- # 
    # FUNCTION:     create_error 
    # DESCRIPTION:     Creates error messages 
    # 
    # ARGS:         $error        (mixed)  error message[s] 
    #                 $type        (string) type of error 
    # 
    # RETURNS:        VOID 
    #                Sets $obj->error and $obj->error_array 
    # ----------------------------------- # 
    
function create_error($error$type='') { 
        
$this->error ereg_replace("<br>$"""$this->error); 
         
        if (
$type == "validate_fields") { 
            
$r "<b>Please fill in the following fields:</b><br>\n"
            foreach (
$error as $v) { 
                
$i  1
                
$r .= "&nbsp;&nbsp;&nbsp;•&nbsp;"
                
$v_array explode("||"$v); 
                foreach (
$v_array as $c) { 
                    if (
trim($c)) { 
                        if (
$i 1) { $r .= " <b>or</b> "; } 
                        
$missing_fields[] = $c
                        
$r .= ucwords(eregi_replace("_"" "$c)); 
                        
$i++; 
                    } 
                } 
                
$r .= "<br>\n"
            } 
            
$this->error .= $r
            
$this->error_array['missing_fields'] = $missing_fields
         
        } elseif (
$type == "message") { 
            if (!
$this->error_array['message']) { 
                
$this->error .= "<b>The following errors occured:</b><br>\n"
            } 
            
$this->error .= "&nbsp;&nbsp;&nbsp;•&nbsp;" $error "<br>\n"
            
$this->error_array['message'][] = $missing_fields
        } 
        
$this->error .= "<br>"
        
$this->error_message $this->error
    } 


/* 
<readme> 
     
    Validator Class is a PHP object that can be used to validate 
    the presence of HTML form data. 
     
    By "validating", the function simply checks if a variable is 
    NOT NULL. The class is intended to be called AFTER the end-user 
    has submitted an HTML form. 
     
    The class is first initiated, then the validate_fields function 
    is called by passing the field names of all the required form 
    fields. If any of the variables (field names) are NULL the 
    function returns FALSE, along with an error message of which 
    fields are null. If all the variables are NOT NULL, the function 
    returns TRUE. 
     
    # --------------------------------------------------------------- # 
    # VALIDATOR CLASS USAGE 
    # --------------------------------------------------------------- # 
    - Start a new instance of the object: 
      $my_validator = new validator(); 
     
    - Check for the presence of data in one variable named $my_variable 
      $my_validator->validate_fields("my_variable"); 
     
    - Check for the presence of data in three variables 
      named $first_name, $last_name, and $email 
      $my_validator->validate_fields("first_name, last_name, email"); 
     
    - Check for the presence of data in at least one check box. There 
      are 3 checkboxes on the form ($ch_1, $ch_2, and $ch_3) 
      $my_validator->validate_fields("ch_1||ch_3||ch_3"); 
     
    - Check for the presence of data in at least one check box, 
      AND each of 2 text fields: 
      $my_validator->validate_fields("ch_1||ch_3||ch_3, text_1, text_2"); 
       
    - Printing Errors 
        if (!$my_validator->validate_fields("last_name, email")) { 
            echo $my_validator->error; 
        } else { 
            ... 
        } 
     
    # --------------------------------------------------------------- # 
    # VALIDATOR CLASS SET UP 
    # --------------------------------------------------------------- # 
    The only set up is to include this file on the page that you're 
    using it 

</readme> 
*/ 
?>


If you or someone else can help me to get this thing done, I would be very grateful.

Thanks again

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Web form using php to import into Access db


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway