SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    single page with multiple data entries

    guys..

    I want to create a page that allows the user to input many fields.. like name, address, contact number and so on.

    Upon hitting a Submit button, I want all that info. to be stored in a database, and the page refreshed to display the updated contents. something like on this site.. where I type stuff in many fields.. and then I get to see the posts automatically (on the same page).

    So far, I can do this with one field per form, like this:

    <form method="POST" action="pdc_edit_own2.php">
    Start of Vacation Date (YYYY-MM-DD):
    <input type="text" name="start_vac">
    <input type="submit" value="Submit">
    </form>

    The trouble is that the user needs to go enter data, click submit, see a new page, enter data, click submit... and so on. It would be better to have him enter all data on a page and then click submit once.

    Any ideas.... I would appreciate a general syntax, and explanation as HTML isn't my forte!

  2. #2
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Um not maybe the sweetest route but it works...

    create two pages
    1. plain html...
    <FORM TITLE="test" ACTION="store.php" METHOD="POST">
    First NameINPUT TYPE="text" NAME="firstname" SIZE="25" MAXLENGTH="50" >
    Last NameINPUT TYPE="text" NAME="lastname" SIZE="25" MAXLENGTH="50" >

    ... include as many forms elements as you want then at the bottom...
    <INPUT TYPE="submit" NAME="submit" VALUE="send">
    </FORM>

    then Page 2... html with php called "store.php" (exactly the same as above but where you had the <INPUT TYPE> put in <?php echo($);?> with the name of the form element inside it.. see below

    First Name?php echo($firstname) ; ?>
    Last Name?php echo($lastname) ; ?>

    which when clicked on this first page will show the next page with all the detail filled in.

    Hope that this helps (if you need the whole page let me know I can email thme to you)

    Sarah

  3. #3
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin's tutorial will be a good help to you specially
    this chapter.

    Hope that helps.

  4. #4
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sarah

    create two pages
    1. plain html...
    <FORM TITLE="test" ACTION="store.php" METHOD="POST">
    First NameINPUT TYPE="text" NAME="firstname" SIZE="25" MAXLENGTH="50" >
    Last NameINPUT TYPE="text" NAME="lastname" SIZE="25" MAXLENGTH="50" >

    ... include as many forms elements as you want then at the bottom...
    <INPUT TYPE="submit" NAME="submit" VALUE="send">
    </FORM>

    then Page 2... html with php called "store.php" (exactly the same as above but where you had the <INPUT TYPE> put in <?php echo($);?> with the name of the form element inside it.. see below

    First Name?php echo($firstname) ; ?>
    Last Name?php echo($lastname) ; ?>

    which when clicked on this first page will show the next page with all the detail filled in.


    Sarah

    Great idea Sarah, but I managed to get it to work using a diff. approach I did the following:

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    Start of Vacation Date (YYYY-MM-DD):
    <INPUT TYPE="text" NAME="start_vac">
    <BR>
    End of Vacation Date (YYYY-MM-DD):
    <INPUT TYPE="text" NAME="end_vac">
    <BR>
    Contact Person/s:
    <INPUT TYPE="text" NAME="contact">
    <BR>
    Comment/s:
    <INPUT TYPE="text" NAME="comment">
    <INPUT TYPE="submit" VALUE="Submit">
    </FORM>

    Upon hitting 'Submit', the page would reload and echo calls to the following would work:

    $start_vac
    $end_vac
    $contact
    $comment
    $Submit

    But now I have a new problem! These commands are on page 3. On page 1 (the main page), I have the user key in his ID number. I would like that ID number to be "remembered" thruout the pages from start to end (i.e.: An "immortal" variable). I managed to do just that using Session Registers, but it seems that my ID number cannot be called when the page refreshes itself using the php echo($PHP_SELF) function!

    Any ideas? FreakSid.. if you're reading this, would gladly appreciate your input!

    Thanks guys!
    Last edited by infinitium; Jul 8, 2001 at 17:18.

  5. #5
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have a look through kevin's tutorial end of Part 3..

    basically this is some code which you should be able to do this...

    <A HREF="newpage.php?name=<?php echo(urlencode($name)); ?> A link </A>

    I am sure that you can alter this to fit into your FORM code also?

    I also know that you can do this using a HEADER function (can't find the details as yet but I shall keep looking.

    Good luck

    Sarah

  6. #6
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to access your ID numbers on all pages when using sessions, even if the form is submitted to the same page. Make sure you are using session_start(); on everypage you wish your variable to be present.

    Other than that, and it is still not present, put a hidden field in your form with the ID in it, so that you can use this when the form is submitted. This does provide a security whole however.

    <input type="hidden" name="id" value="<?=$id?>">

    This will also provide a way to see if your variable is being passed to this page in the first place as well.

  7. #7
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by timnz
    You should be able to access your ID numbers on all pages when using sessions, even if the form is submitted to the same page. Make sure you are using session_start(); on everypage you wish your variable to be present.

    Other than that, and it is still not present, put a hidden field in your form with the ID in it, so that you can use this when the form is submitted. This does provide a security whole however.

    <input type="hidden" name="id" value="<?=$id?>">

    This will also provide a way to see if your variable is being passed to this page in the first place as well.
    A question on sessions. I do specify session_start() at the beginning of every page, regardless whether I use it or not. I've read somewhere that it's best to do this.. no harm anyway!

    But what's the deal with session_register()? Can I session_register() more than 1 variable? Let's say on a page..... I do the following:

    session_register($id_own);
    session_register($address_own);
    session_register($name_own); ......

    ... and so on. Would this be acceptable? Meaning on all susequent pages, ECHOs to these variables would work?

    Sarah: The urlencode() fn. only passes a URL.. haven't figured out how to immortalize a variable yet!

    Am still wondering why my php echo($PHP_SELF) , when it refreshes the page to reflect new info, will NOT display any session registered stuff? (even though session_start() is specified at the top of the page).....


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
  •