Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: universal form

  1. #1
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default universal form

    I am working on something right now and I am not sure if it's even possible. I was wondering if someone can help me out on this?

    I have 1 form page and I want to make an option (drop down list) that when the user chooses an option from the drop down it changes the outcome of the submit.

    My idea is as follows.

    When someone selects an option from the drop down it changes the link on the submit button i.e. (if the drop down option b02 is selected, then when the user hits the submit button it uses php page b02.php. And the same for b04 = b04.php, b05 = b05.php.

    Is this possbile? If so can anyone point me in the right direction?

    Please and Thanks.

    -- Nate

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I think it would be easier to have a hidden input that you can change the value of. Then, when the form is proccess, it can redirect them. Or, you could include all of the possibilities in one php page, then process the form.

    PHP Code:
    if(isset($_POST['hidden_input'])){
        
    $hidden $_POST['hidden_input'];
        switch(
    $hidden){
            case 
    'b01':
              
    //do something
           
    break;
            case 
    'b02':
              
    //do something
           
    break;
        }

    The JS would be something like:
    Code:
    function changehidden(thevalue){
        document.form.hidden_input.value = thevalue;
    }
    <select name="dropbox" onchange="changehidden(form.dropbox.options[selectedIndex].value)">
         <option value="b01">b01</option>
         <option value="b02">b02</option>
    </select>
    (I think, but it's been a while since I've done something like that. If it doesn't work, let me know.)

    Edit: wrong js code, fixed I think
    Last edited by Jas; 03-03-2008 at 09:39 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Jas

    The reason I was thinking of using different php pages is when someone submits the form I have a webmaster recieve an html email designed like a card that displays the persons name, address, email, etc.

    But the email the webmaster gets has a code on the botom right of the card that represents the persons selection from the drop down.

    I was thinking of hidden fields but am kind of new to that aspect and not sure how to do it. But if that would be easier I would prefer to do that.

    I hope my explanation makes sense.

    -- Nate

  4. #4
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I am a little lost. I still think the way shown in my last post would work, unless I don't understand it. (I also fixed the code, cause it was wrong ).
    PHP Code:
    if(isset($_POST['hidden_input'])){ 
        
    $hidden $_POST['hidden_input']; 
        switch(
    $hidden){ 
            case 
    'b01'
              
    // PAGE b01.php's contens can go here, or you can use:
              //header("Location: ./b01.php");
              // to redirect or
              // include('./b01.php');
              // to pull in the files contents
           
    break; 
            case 
    'b02'
              
    //do something 
           
    break; 
        } 

    Basically, the hidden input is a hidden input that the user cannot see or manipulate as they can with other input types. But, via JS, you can change the value according to their selection on the dropbox. See the JS code on my post above.
    Last edited by Jas; 03-03-2008 at 09:42 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  5. #5
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Hey Jas,

    This might be asking a bit much but the code you used, is it possible to see a demo? I am still learning parts of this and I am not sure where to drop the php code on the page.

    If not an example like a tutorial page to figure it out a bit better?

  6. #6
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Sure. Give me a second to make one for you. I won't be able to test it right now, so there *may* be an error. If there is, just let me know. I'll post it in a little bit.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #7
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Okay, try running this:

    PHP Code:
    <?php

    //has the form been submitted?
    if(isset($_POST['submit'])){

        
    //set the var $hidden equal to the value of the hidden field
        
    $hidden $_POST['hidden_input'];

        
    //start up a switch statement to check $hidden
        
    switch($hidden){

            
    //if the value of $hidden is b01
            
    case 'b01':
                echo 
    'This is form process 1';
            break;

            
    //if the value of $hidden is b02
            
    case 'b01':
                echo 
    'This is form process 2';
            break;

            
    //none of the other options worked
           
    default:
                echo 
    'There was an error processing the form';
           break;

        }
    //end switch
    }//endif

    ?>

    <script>
    function changehidden(thevalue){
        document.form[0].hidden_input.value = thevalue;
    }
    </script>

    <form method="post" action="">

        <input type="hidden" name="hidden_input" />

       <select name="dropbox"
            onchange="changehidden(form[0].dropbox.options[selectedIndex].value)">
         <option value="b01">b01</option>
         <option value="b02">b02</option>
       </select>

        <input type="submit">
    </form>
    Tell me what it does. I am worried about the Javascript part. . . I think it will work, though.

    You can replace echo "This is form process #" with whatever you want the form to do.
    Last edited by Jas; 03-04-2008 at 03:39 AM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  8. #8
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Yeah...

    Is there a tutorial page for this? Because I am lost.

  9. #9
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    We all get lost at some point-- I'm experiencing that feeling with Linux right now.

    Anyway, let what do you want to know specifically, and I'll do my best to explain it. There is no tutorial for this particular subject-- not that I know of, at least. I'm not sure what level your at as a coder, so you'll have to let me know what you need help on. I can find tutorials for you on different aspect of this, if you need me to.

    BTW: Did you get the script to run? It might help you see what's happening. Paste the code into a file named "something.php" and put it on a PHP enabled server, if you haven't already.
    Last edited by Jas; 03-05-2008 at 02:28 AM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  10. #10
    Join Date
    Dec 2007
    Location
    Mississauga
    Posts
    166
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Hey Jas,

    I pasted the php code in Dreamweaver and got the drop down part in visuals but for the code aspect I am just confused with...
    Code:
    echo 'This is form process 2';
    I am not sure what to place in there.

    I can paste the code I am using right now on the pages if that helps with implementing it. I will have to get to it in a few hours though.

    -- Nate

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
  •