SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Put a $_POST into a Object

    Heya, Im kind of a newbie with classes and I was wondering is there a way I can get the POST to echo into my object here?

    PHP Code:
    $name $_POST['name'];

    // See how I try to echo it into there at the end for the value??
    $form->make('Name''name''text''25', echo $name); 
    This is the class but I don't think you need to see it
    PHP Code:
    // The part of the class is here:
    function make($title$name$type$size$value) {
            
    $this->form .= "<label for=\"$name\">$title</label> \n";
            
    $this->form .= "<input type=\"$type\" name=\"$name\" value=\"$value\" size=\"$size\" /><br /> \n\n";
            } 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You just pass the variable along...

    $form->make('Name', 'name', 'text', '25', $name);

    or

    $form->make('Name', 'name', 'text', '25', $_POST['name']);

    Dont forget to escape it if its for display later:
    PHP Code:
    function make($title$name$type$size$value "") {
            
    $this->form .= "<label for=\"$name\">$title</label> \n";
            
    $this->form .= "<input type=\"$type\" name=\"$name\" 
            value=\""
    htmlentities$value 
            .
    "\" size=\"$size\" /><br /> \n\n";
            } 
    (made it multiline so its a bit more readable)

    By making value have a default value, with $value = "", you can now use the same method when there is no value for value.

    $form->make('Name', 'name', 'text', '25'); // making a blank form element

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh that is really cool I never would think of doing a value="" in the function attributes. It works great now

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Watch out though, you have to work from the right hand side argument.

    So you could for example set $size=25 next.

    http://www.php.net/manual/en/functions.arguments.php

    You should really know everything there is to know about functions, then as you know, when used in classes they are magically called methods.

    Its worth spending time on these man pages, well worth it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •