Form fields values to php variables in the same page

Discussion in 'PHP' started by getquicksolution, Apr 22, 2010.

  1. #1
    How can we assign the form fields values to php variables in the same page???
     
    getquicksolution, Apr 22, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    You'll need to explain that a bit better.

    All form fields that have a value will be submitted and available to your PHP script through the $_GET variable or the $_POST variable.

    It might be an idea to post your code and we'll be able to answer more clearly.
     
    sarahk, Apr 22, 2010 IP
  3. getquicksolution

    getquicksolution Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually i dont want to sumit form,so i dont want to use $_GET or $_POST.
    I meant for example i have a page named mypage.php
    and in this page i have made a form using
    echo"<form name='form1'> <input type='text' name='name'></form";
    then if i want to assign value document.form1.name.value like this:
    $var= document.form1.name.value;

    how can it be possible???
     
    getquicksolution, Apr 23, 2010 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    PHP is used to construct the page and to give the <input> a value. By the time the user fills it in the PHP script is finished. If you want to do any validation you have to either
    * submit the form
    * use javascript
     
    sarahk, Apr 23, 2010 IP
  5. ashraful88

    ashraful88 Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    Use a if-else condition to do that.
    'isset' checks the submit button pushed or not.

    if(isset($_POST['go']))
    {
    $input1=$_POST['input1'];
    $input2=$_POST['input2'];
    ...................
    }
    else{
    echo " your html form here, where name of submit button is go ";

    }

    Hope this will help you.
     
    ashraful88, Apr 23, 2010 IP
  6. System 6 Hosting

    System 6 Hosting Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you want the value to be assigned while in the same page you just need the form action on submit to reload the page. This can be done without using a submit button using javascript events. So unless the page takes a long time to reload it's pretty transparent to the end user.
     
    System 6 Hosting, Apr 23, 2010 IP