set $_SESSION ['someth'] on Submit
Results 1 to 10 of 10

Thread: set $_SESSION ['someth'] on Submit

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    14

    set $_SESSION ['someth'] on Submit

    Hi,

    i need to set up $_SESSION ['someth']= true when user click the SUBMIT button.
    How can I make this?

  2. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Brazil
    Posts
    225
    session_start() doesn't work?
    PHP Code:
    while (2*== 5) {
          echo 
    "If you're reading this something is definitely wrong";


  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,398
    PHP Code:
    if(isset($_POST['submit_button_name']))
        
    $_SESSION['someth'] = true

  4. #4
    Junior Member
    Join Date
    Jan 2008
    Posts
    14
    Quote Originally Posted by Jack McSlay
    session_start() doesn't work?
    Yes, but what I mean is that, how can I implement it to submit button
    <input type='submit' value='Submit' name='Submit' and now set $_SESSION['someth'] />

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,398
    You can't - PHP is a server-side language, and HTML/JavaScript is a client-side language. You have to send data back to the server so that it knows when the submit button was pressed (e.g. via AJAX or by submitting the form). PHP alone doesn't know what a submit button is, let alone when it was clicked.

  6. #6
    Junior Member
    Join Date
    Jan 2008
    Posts
    14
    Quote Originally Posted by bradgrafelman
    PHP Code:
    if(isset($_POST['submit_button_name']))
        
    $_SESSION['someth'] = true

    I want to prevent refreshig the page after inserting data into database and opening formular page without pressing the insert button.
    So I need set $_Session to true before showing the insert form (and by showing test if $_Session is true) and after inserting data destroy the $_Session

  7. #7
    Senior Member LiamBailey's Avatar
    Join Date
    Nov 2007
    Posts
    133
    I'm no expert but you could try starting the page with
    <? if (!$_SESSION['someth'] || $_SESSION['someth'] != "true") {
    session_start();
    $_SESSION['someth'] = "true";
    header( "Location: $_SERVER['PHP_SELF']" );
    }

    that means:

    if there is no someth stored in the session data, or it is stored but doesn't equal true, store it with the value true then refresh the page, at which point the if argument wouldn't run and the page would load as normal.

    If you want to do it using javascript you would need to use cookies

    put <form name="the_form" action="" method="post" onSubmit="setcookie()"?

    And in the <head> section of your page put

    <script language="javascript">
    <!--------
    function setcookie() {
    var the_cookie = "someth=true";
    document.cookie = the_cookie;
    }
    //--------
    </script>
    You can then access the cookie from php using: $_COOKIE['someth'];

    I hope this helps

  8. #8
    Geek
    Join Date
    Jul 2007
    Posts
    780
    You want to use ajax here, if you need to submit a form without refreshing the whole page.

  9. #9
    Self Proclaimed King rulian's Avatar
    Join Date
    Feb 2001
    Location
    New Jersey
    Posts
    907
    You have to understand you cannot perform PHP function from HTML.
    When you look at a website on your computer, everything you are looking at is actually on YOUR computer. The HTML/Javascript and Imagery is all downloaded form the server to the client (meaning YOU) That is why HTML and Javascripting is called a Client side language, because it is executed by the user (client (meaning you))
    Anything interactive, such as a form submit button is done on the client side.

    PHP is a server side language. Meaning the server will handle the PHP file, your computer never sees the PHP, it only sees what the HTML the server spit out to it.

    Because then your computer never sees the PHP and the server doesnt read the HTML once its on your machine those two cannot interact.

    That is until AJAX

    AJAX is not a language, it is basically a method in Javascript to send and recieve things from the server without leaving the client side area, or refreshign the page.

    So it works as a bridge between you the client and the server
    new site, check it http://www.rockstarcode.com/

  10. #10
    Senior Member
    Join Date
    Jun 2005
    Location
    Brazil
    Posts
    225
    whenever you click a submit button, the browser sends the content of the form to whatever is on the "action" attribute of the form (or sends back to the current location if the attribute is absent). So I don't see why there is a need for the submit button to perform extra actions, as you can just make the receiving script do what you want
    PHP Code:
    while (2*== 5) {
          echo 
    "If you're reading this something is definitely wrong";


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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