45 users online (0 members and 45 guests)  


  Results 1 to 15 of 15

Related

  1. Replies: 1
  2. Replies: 4
  3. Replies: 1
  4. Form Handling Script for 'Tell A Friend' Form    Forum: Javascript Forum
    Replies: 1
  5. Replies: 3
  1. #1
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    form help please

    Hello, I hope someone can help point me in the right direction.
    I am building a multi page form. The first page has three options(below). What I need is for the user, upon clicking the "Next Page" button be directed to either a supportscsi.php page, supportfibre.php page or a supportiscsi.php page, depending on what technology option they have chosen. I am unclear on what PHP code to put in the beginning of the form for form metod and post, the three options and the "Next Page" name section.
    <FORM METHOD=POST ACTION="/techsupt2.php" NAME="register">

    <select name="Technology">
    <option value>-----Please select-----</option>
    <option value="Fibre">Fibre Channel</option>
    <option value="SCSI">SCSI</option>
    <option value="iSCSI">iSCSI</option>
    </select>

    <input type="submit" value="Next Page" name="" />
    I appreciate any help. Thank you in advance.

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: form help please

    Quote Originally Posted by bufhal
    <FORM METHOD=POST ACTION="/techsupt2.php" NAME="register">
    <select name="Technology">
    <option value>-----Please select-----</option>
    <option value="Fibre">Fibre Channel</option>
    <option value="SCSI">SCSI</option>
    <option value="iSCSI">iSCSI</option>
    </select>

    <input type="submit" value="Next Page" name="" />
    I appreciate any help. Thank you in advance.
    Try something like
    PHP Code:
    <?php
    if ($_POST['Technology'] == "Fibre") { header("Location: fibre.php"); }
    elseif (
    $_POST['Technology'] == "SCSI") { header("Location: scsi.php"); }
    elseif (
    $_POST['Technology'] == "iSCSI") { header("Location: iscsi.php"); }
    else {
    // Deal with incorrect values here if necessary
    }
    ?>
    If page 1 has any more info than just Fibre/SCSI/iSCSI you'll need to expand this to pass the extra info, either using fibre.php?var1=value1&var2=value2 etc or possibly using sessions.
    Alternatively, you can do:
    PHP Code:
    <?php
    if ($_POST['Technology'] == "Fibre") {
    ?>
    CODE FOR FIBRE FORM HERE
    <?php
    } elseif ($_POST['Technology'] == "SCSI") {

    ?>
    CODE FOR SCSI FORM HERE
    <?php
    } elseif ($_POST['Technology'] == "iSCSI") {

    ?>
    CODE FOR iSCSI FORM HERE
    <?php
    }
    ?>
    but you'd need to remember to pass the "Technology" value as a hidden item in the form, and do the same for each set of info passed by each page

  3. #3
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: form help please

    P.S. I'm only 99% certain about the header syntax - you'll need to check that.
    It redirects to a new page based on the values passed by the form - and you'll also need to ensure that nothing is output before the command - this includes white space.

  4. #4
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    thank you

    This is the start of my form:
    <FORM METHOD=POST ACTION="" NAME="register">
    And this is the end of the form for submit where it should redirect to one of the three pages:
    <input type="submit" value="Next Page" name="Technology" />

    Not sure about what I should put in these

  5. #5
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: thank you

    This is your existing code for the "menu" page. It is fine as it is.
    HTML Code:
    <FORM METHOD=POST ACTION="/techsupt2.php" NAME="register">
    <select name="Technology">
    <option value>-----Please select-----</option>
    <option value="Fibre">Fibre Channel</option>
    <option value="SCSI">SCSI</option>
    <option value="iSCSI">iSCSI</option> 
    </select>
    <input type="submit" value="Next Page" name="" />
    This is the code for the techsupt2.php page.
    PHP Code:
    <?php 
    /* Redirect to a different page in the current directory that was requested */ 
    $host  $_SERVER['HTTP_HOST']; 
    $uri  rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); 
    $tech $_POST['Technology'].".php"
    if (
    $tech == "-----Please select-----.php") { $tech "techsupt.htm"; } // Replace "techsupt.htm" with the name of your first form page if necessary. 
    header("Location: http://$host$uri/$tech"); 
    exit; 
    ?>
    Now you need to create 3 pages -
    Fibre.php
    SCSI.php
    iSCSI.php

    which are your menu pages for the three technologies you have offered.
    The techsupt2.php has no output, other than a redirect to the page you selected, or back to the menu page (techsupt.htm) if you left the drop-down at -----Please select-----
    You can expand on this, but what is there works so far - I've tested it with blank pages to make sure the redirection works.
    Hope that helps,
    DMGF
    Last edited by DeadMeatGF; 06-15-2006 at 09:44 AM.

  6. #6
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    Re: form help please

    Thank you, Deadmeat. I have most of it in place. I appreciate your help..

  7. #7
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    Re: form help please

    Thanks, I am close but still a bit off>
    This is the fiirst form page:
    <FORM METHOD=POST ACTION="/rontest.php" NAME="register">
    <select name="Technology">
    <option value>-----Please select-----</option>
    <option value="support_fibre.php">Fibre Channel</option>
    <option value="support_scsi.php">SCSI</option>
    <option value="support_iscsi.php">iSCSI</option>
    </select><br><br>
    <input type="submit" value="Next Page" name="rontest.php" />
    I created a HTML page for the redirect with your PHP and changed the URL:
    PHP Code:
    <?php 
    /* Redirect to a different page in the current directory that was requested */ 
    $host $_SERVER['HTTP_HOST']; 
    $uri rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); 
    $tech $_POST['Technology'].".php"
    if (
    $tech == "-----Please select-----.php") { $tech "support-ron.php"; } // Replace "techsupt.htm" with the name of your first form page if necessary. 
    header("Location: http://$host$uri/$tech"); 
    exit; 
    ?>
    And finally, I have three landing form pages for the three technologies:
    support_scsi.php
    support_iscsi.php
    support_fibre.php

    Not working yet,

  8. #8
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: form help please

    Aha!
    You've added the ".php" to the <OPTION> tags.
    If you take the ".php" out of the <OPTION> tags it should be spot on.
    The line
    PHP Code:
    $tech $_POST['Technology'].".php"
    adds ".php" to whatever is in the "Technology" value from the form, so it's trying to find support_scsi.php.php (etc.)
    I did it that way to make it easier to redirect to the form if the user has left the drop-down on "-----Please Select-----", you could take the ."php" out of the above line, but you'd have to also alter the following line, so it's easier to take it out of the <OPTION> tags
    Last edited by DeadMeatGF; 06-16-2006 at 02:42 AM.

  9. #9
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    thank you

    Thanks for your help. It works!
    I really appreciate your help!

  10. #10
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: thank you

    Excellent

  11. #11
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    help with one last challenge?

    Got this thing working with your help except one snag. If you can spare anymore time, your help would be more than greatly appreciated. If not, I understand.
    If so....Since the button on the first form page just redirects (does not submit info to the next form), is there a way to capture the data from the first page and add to the info captured on the 2nd page? The tech support group want this two page format. These pages enter the info into Goldmine and I still have to get the fields lined up for that but I wondered if PHP code could be added to the "Next Page" button that would also submit the first page info and add the info from either of the three technology pages.first form with information I want captured and added to 2nd page. I am sure there is probably many other ways to do this but I'm not sure if the button could redirect, and post.

    <FORM METHOD=POST ACTION="rontest.php" NAME="register">
    example of one of the fields I want captured and added to 2nd page.

    <td width="41%" height="15" valign="top"><font color="#FF0000">*</font> <b>First name:</b></td><td width="59%" height="15" valign="top"><INPUT NAME="CONTACT" SIZE="50" value=<?echo("\"$first_name\"");?>></td></tr>

    This is the bottom I modified at your suggestion to get it working
    <select name="Technology"><option value>-----Please select-----</option><option value="support_fibre">Fibre Channel</option>
    <option value="support_scsi">SCSI</option>
    <option value="support_iscsi">iSCSI</option>
    </select><br>
    <input type="submit" value="Next Page"

    name="rontest.php" \>

    I am scouring PHP.NET and the web to find out how to do this. Please let me know if you have any ideas.
    Thank you..

  12. #12
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: help with one last challenge?

    If the
    HTML Code:
    "<INPUT NAME="CONTACT" SIZE="50" value=<?echo("\"$first_name\"");?>>
    is in the same <form>...</form> as the
    HTML Code:
    <select name="Technology"><option value>-----Please select-----</option><option value="support_fibre">Fibre Channel</option>
    <option value="support_scsi">SCSI</option>
    <option value="support_iscsi">iSCSI</option> 
    </select>
    then you can capture it (and any other form elements) on the next page using
    PHP Code:
    $_POST['field_name'
    obviously replacing field_name with the actual name of the element (e.g. CONTACT)
    As the form (as you correctly pointed out) leads into a redirect, you have three options ...
    1. Make the redirect page into a <form> with hidden elements duplicating the data from the original form. The disadvantage is that you now have two clicks to get to the next page, probably disguised as an "Are you sure you want this technology" button - but still slightly annoying for the user.
    2. Pass the form variables as a session, using (for example)
      PHP Code:
      $_SESSION['CONTACT'] = $_POST['CONTACT'
      before the header redirection - see http://uk2.php.net/manual/en/ref.session.php
    3. Pass the data through the URL - e.g.
      PHP Code:
      $url="http://www.xxx.yyy.php?c=".$_POST['CONTACT']."&x=".$_POST['x'];
      header("location: $url"); 
      The disadvantage here is the the values become visible, so they're either easy to snatch or you have to encrypt them.

    I believe you can also pass variables in the headers, but I've never tried this, so I'm ignoring that option - of the three above, sessions are the best, as once the variable is stored in the session, you can access it on all future pages until you clear the session, or the user closes the browser.
    Last edited by DeadMeatGF; 06-19-2006 at 04:50 AM.

  13. #13
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    Re: form help please

    thanks again. I will try to use the sessions. One last question:
    if this code:
    $_SESSION['CONTACT'] = $_POST['CONTACT']
    goes on the first form page, how do I grab it on subsequent pages?

    Thanks Deadmeat!

  14. #14
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: form help please

    At the head of every page, the first line after <?php should be session_start();
    Once you've done that, $_SESSION is a superglobal array, and can be accessed from any page, script, function etc.
    So you can just use it - eg
    PHP Code:
    <?php
    session_start
    ();
    echo 
    "Howdy ".$_SESSION['CONTACT'].", what would you like help with today?<br />";
    ?>

  15. #15
    bufhal's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2006
    Posts
    32

    Re: form help please

    Thank you very much for your help.



Tags for this Thread