SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: $post

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $post

    Hello.

    I need :

    1. Get $POST value
    2. Assign it to variable
    3. Request another $POST
    4. Refer to previous $POST value.


    Does it possible?

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,580
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Do you mean $_POST?

    // 1. Get $POST value
    // 2. Assign it to variable
    PHP Code:
      $value_001 = isset($_POST['value_001']) ? $_POST['value_001'] : 'EMPTY AND/OR NOT SET'

    // 3. Request another $POST
    // 4. Refer to previous $POST value.

    Take a look at: http://www.w3schools.com/php/php_forms.asp

    and:
    http://www.w3schools.com/php/php_post.asp



    .

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nydiann View Post
    Hello.

    I need :

    1. Get $POST value
    2. Assign it to variable
    3. Request another $POST
    4. Refer to previous $POST value.


    Does it possible?
    Using filter_input does all of the above, and is the recommended way these days as you can specify types of filters to use, to specify sanitisation and validation requirements.

    Code php:
    $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For example :

    2 forms
    Code PHP:
    echo '<form action="index.php" method="post">
    Name: <input type="text" name="fname" />
    Age: <input type="text" name="fage" />
    <input type="submit" />
    </form>';
     
     
    echo '<form action="index.php" method="post">
    Name: <input type="text" name="lname" />
    Level: <input type="text" name="lage" />
    <input type="submit" />
    </form>';

    Assign to variables like you said

    Code PHP:
    $fname = filter_input(INPUT_POST, 'fname', FILTER_SANITIZE_STRING);
    $age = filter_input(INPUT_POST, 'fage', FILTER_SANITIZE_STRING);
    $name = filter_input(INPUT_POST, 'lname', FILTER_SANITIZE_STRING);
    $level = filter_input(INPUT_POST, 'lage', FILTER_SANITIZE_STRING);


    Then echo it

    Code PHP:
    echo "\$_POST['fname'] = $fname";
    echo '<br /><br />';
    echo "\$_POST['age'] = $age";
    echo "<p style='color:green; font-weight: bold'>***********************</p>";
    echo "\$_POST['lname'] = $name";
    echo '<br /><br />';
    echo "\$_POST['lage'] = $level";


    But When I submit first form , second is getting erased.
    Any way to keep $_POST value from first form after submiting another one?

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, store anything you want to persist across multiple pages in the session
    PHP Code:
    session_start(); // must be called before any output to browser
    $_SESSION['whatever'] = ['something']; // $_SESSION['whatever'] will keep it's value till session times out 

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks , that's helped.


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
  •