Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with form handler...

    Im sorry if this is a noob question but i am having trouble with a part on my site.. I have created a dropdown menu and a submit button. The options in the dropdown menu are pages on my site. I want the customer to be able to choose and option and when they click submit it will go to that page.. How do i do this? do i need to do it with a form handler or is there a easier way.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Can you post your form code? Ideally you can use a form handler and then you can use javascript only AFTER your form handler is working without javascript. Does your webhost support PHP?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Can you post your form code? Ideally you can use a form handler and then you can use javascript only AFTER your form handler is working without javascript. Does your webhost support PHP?
    you can check it on newcastlefitness.com.au.. its the main part where it says "select activity"

    this is the code i have so far, im pretty sure my host supports PHP but unsure.

    <option>Select the type of Activity</option>

    <option value="Zumba Classes">Zumba Classes</option><option value="Senior Fitness">Senior Fitness</option><option value="Pilates">Pilates</option><option value="Personal Training Newcastle">Personal Training Newcastle</option><option value="Gyms in Newcastle">Gyms in Newcastle</option><option value="Self Defence">Self Defence</option><option value="Yoga Classes">Yoga Classes</option><option value="Kids Fitness">Kids Fitness</option><option value="Boxing">Boxing</option><option value="MMA">MMA</option><option value="Swimming">Swimming</option><option value="Cycling">Cycling</option><option value="Crossfit in Newcastle">CrossFit in Newcastle</option><option value="Bootcamps">Bootcamps</option><option value="Woman Only">Woman Only</option><option value="Corporate Fitness">Corporate Fitness</option><option value="Kick Boxing ">Kick Boxing </option><option value="Running">Running</option> </td>
    </tr>

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    There are a few ways to do this with your current setup. You can have a php processing script that will take the value and redirect user based off the value they selected. You could also modify your values to be the actual pages that you want the user to go to, and then use a php processing script to just redirect the user to the url in the value. Either way you will need some kind of form handler. Make the action in your form point to process.php e.g.
    Code:
    action="process.php"
    Then upload this to the same location as your html page on your site and call it process.php
    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_POST['submit_x']) && isset($_POST['submit_y']))
    {
        
    /* This is the array with valid values from your form, follow the format the below. */
        
    $allowed = array(
                         
    'Senior Fitness'=>'senior_fitness_url_goes_here',
                         
    'Pilates'=>'pilates_url_goes_here',
                         
    'option_value'=>'url_for_that_value_goes_here'
                        
    );
        
        
    /* You do not need to edit below this line */
        
    $selection htmlentities(strip_tags($_POST['specialty']));    
        if(!
    array_key_exists($selection,$allowed))
        {
            
    $_SESSION['error'] = "That is not a valid selection. Please try again.";
            
    header("Location: index.php");
            exit();
        }
        
    $location $allowed[$selection];
        
    header("Location: $location");
        exit();
    }
    ?>
    I've started populating the array for you. You can do the rest. On your index.php page add session_start(); to the very top just after <?php, then add this inside of your form
    PHP Code:
    <?php
    if(isset($_SESSION['error']))
    {
    echo 
    $_SESSION['error'];
    unset(
    $_SESSION['error']);
    }
    ?>
    Change this
    Code:
    <img src="http://www.newcastlefitness.com.au/wp-content/uploads/2012/01/search-button-green.png" alt="Coming Soon" width="122" height="62"/>
    to this
    Code:
    <input type="image" name="submit" src="http://www.newcastlefitness.com.au/wp-content/uploads/2012/01/search-button-green.png" alt="Coming Soon" width="122" height="62"/>
    If you find that your form is not submitting in IE then you need to add an hidden field.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    stephen_ (01-23-2012)


  •  

    Posting Permissions

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