Is there a way to get the data from an registration form by counting the inputs and textfields but excluding the submit and hidden ones? Lets say I have a form with 5 input fields that contains the data for registration can I make an array for all so when I process the data instead of:

interface userAction {
    public function login();
    public function logout();
    public function isActive();
    **public function addUser($first_name, $last_name, $email, $password, $username, $company_name, $company_address, $zip_code, $city, $country, $phone, $uid, $userIP, $user_level);**
}

I can do: public function addUser($data); <- $data is assoc array

Are you referring to a constructor function that is used when creating new objects of a class? For example:

class User
{
    private $first_name;
    private $last_name;
    private $email;

    public function login() { ... }
    public function logout() { ... }

    public function __construct($data) {
        $this->first_name = $data['first_name'];
        $this->last_name = $data['last_name'];
        $this->email = $data['email'];
    }
}

$myUser = new User($data);
$myUser->login();

Yes something like that I have an interface with user actions and then the classes which implements it such as usercontrol, user, etc.
I did the associative array way, but if I add another field to the registration I want to be able to update the table and the class without making an entire program just for that. There is something that I could for example count the registration fields, retrive the one that has no db table field and automatically update the class for it because the table I got it sorted out to add new field dinamically to it by using a function something like the following:

    // EXAMPLE OF $data array
    // $data = array(
    //     ['name'=>'sql name of the field', 'type'=>'sql data type', 'lungheza/valori'=>'number', 'predefined' => 'sql default'],
    //     ['name'=>'test', 'type'=>'VARCHAR', 'lungheza/valori'=>'255', 'predefined'=>'NULL'],
    //     ['name'=>'test2', 'type'=>'MEDIUMTEXT', 'lungheza/valori'=>'', 'predefined'=>'CURRENT_TIMESTAMP'],
    //     ['name'=>'test3', 'type'=>'INT', 'lungheza/valori'=>'8', 'predefined'=>'UNSIGNED']
    //     );



The only issue that remains is the class

I think that what we do here at DaniWeb is probably close to what you're looking for. Here's a rough example of what we do:

class AllObjects
{

    public function set($properties = array())
    {
        // Loop through properties being passed in
        foreach ($properties AS $property => $value)
        {
            // If property exists for this object type
            if (property_exists($this, $property))
            {                   
                // Update object
                $this->{$property} = $value;
            }
        }   

    }

    /*
     * Constructor function creates a new object of a type that maps to a table in the database
     * and sets the properties for the object
     */
    public function __construct($properties = array())
    {       
        if (!empty($properties))
        {
            $this->set($properties);
        }
    }
}

And then for the specific tables:

class User extends AllObjects
{       
    protected $field1;
    protected $field2;
}

class SomethingElse extends AllObjects
{       
    protected $another_field;
    protected $yet_another_field;
}

Sorry, I forgot to mention how to use it.

With the code above, you can do something like:

$myUser = new User(array(
    'field1' => 'foo',
    'field2' => 'bar',
    'field3' => 'baz'
);

Since class User only has field1 and field2 properties, it will create a new User object with field1 set to foo, and field2 set to bar, and then just silently do nothing with field3 since it doesn't exist.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.