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 11 of 11
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    form action using a GET

    index.php
    PHP Code:
    switch ($_GET['page'])
    {    
        case 
    "home":
            include (
    'pages/home.php');
            break;
            case 
    "search":
                     include (
    'pages/search.php');
                     break;

    the form
    Code:
    <form method="post" action="<? echo $domain; ?>?page=search">
    <input type="text" class="search_bar" name="s" />
    <input type="submit" value="submit" />
    </form>
    search.php
    PHP Code:
    search$_GET['key'] ) ; 


    First I'd like to add that I know the switch statement works, I know the search function works and the form does pass the GET variable if I set the action of the form to the direct php page.

    If I try to set the action to the ?page=search it doesn't pass the variables correctly even though I thought this was alright to do. I'd appreciate any help! This has been irritating me all day.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Not a good idea to mix POST with GET

    Your form has the method defined as "post", so do it like this instead.


    <form method="post" action="<? echo $domain; ?>">
    <input type="hidden" name="page" value="search">
    <input type="text" class="search_bar" name="s" />
    <input type="submit" value="submit" />
    </form>


    $page=$_POST['page'];
    $search=$_POST['s'];
    echo "You are searching $page for $search";

    You'll like using POST because the URL won't have any variables showing in it.

    $_GET is used for seeing the variables in a URL.
    $_POST is most commonly used for submitted forms.
    (although forms can use $_GET ... but not very useful)


    .
    Last edited by mlseim; 02-01-2012 at 11:22 PM.

  • #3
    New Coder
    Join Date
    Nov 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Not a good idea to mix POST with GET

    Your form has the method defined as "post", so do it like this instead.


    <form method="post" action="<? echo $domain; ?>">
    <input type="hidden" name="page" value="search">
    <input type="text" class="search_bar" name="s" />
    <input type="submit" value="submit" />
    </form>


    $page=$_POST['page'];
    $search=$_POST['s'];
    echo "You are searching $page for $search";

    You'll like using POST because the URL won't have any variables showing in it.

    $_GET is used for seeing the variables in a URL.
    $_POST is most commonly used for submitted forms.
    (although forms can use $_GET ... but not very useful)


    .
    Well my index.php is setup so that all my pages are modular. The switch statement actually has a ton more stuff in it, I just didn't want to include every case for the sake of space.

    I can find work arounds such as the method you posted, but I'd rather just do it in a more straight forward fashion. I thought I'd read that you can do it like I'm doing it, I just can't figure out what the problem is.

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    You can do two things:

    Change this code
    PHP Code:
    search$_GET['key'] ) ; 
    to
    PHP Code:
    search$_POST['key'] ) ; 
    or this:
    PHP Code:
    <form method="post" action="<? echo $domain?>?page=search">
    <input type="text" class="search_bar" name="s" />
    <input type="submit" value="submit" />
    </form>
    to
    PHP Code:
    <form method="get" action="<? echo $domain?>?page=search">
    <input type="text" class="search_bar" name="s" />
    <input type="submit" value="submit" />
    </form>

  • #5
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by ramenraider View Post
    Well my index.php is setup so that all my pages are modular. The switch statement actually has a ton more stuff in it, I just didn't want to include every case for the sake of space.

    I can find work arounds such as the method you posted, but I'd rather just do it in a more straight forward fashion. I thought I'd read that you can do it like I'm doing it, I just can't figure out what the problem is.
    The method suggested by mlseim isn't a work around - it's the best solution. It is 'straight forward' because all you need to do is change $_GET['page'] to $_POST['search'] and use the hidden input.

    Like msleim said, you're submitting the form using POST - the browser will send the values in the header as POST. So, passing all your information like this makes the most logical sense.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Is what you're doing an actual "search"?

    You're searching for some string on a page?

    Or, is what you're doing a way of controlling the content on a page?

    Describe what you're doing.

  • #7
    New to the CF scene
    Join Date
    May 2009
    Location
    Miami, FL
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a question about forms, I have one that by a script sends email, fname, lname & phone and sends the data to my email marketing program the problem is that I also need the form to post all the data to an email.

    is there a way to have two actions and 2 methods?

    example here:

    method="post|get" action="/form.php?form=5|email@address.com"

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    One PHP script does both in the same script.

    Send the email first, then do the marketing program thing.

    If I'm understanding you correctly, you have some sort of
    email marketing program that uses GET instead of POST?

    Or, what is your question?

    Show us your actual form, and also
    show us your "form.php" script.

  • #9
    New to the CF scene
    Join Date
    May 2009
    Location
    Miami, FL
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile To your respomce

    The other way around, I have an email marketing program that I am creating a call script for employees to fill in when a prospect call the office to create an appointment.

    After is filled the data goes into a list, the email notification I am getting is only the email address, and I need it to send all data collected.

    Thank you fro your prompt response, and sorry that I'm use to wait for hours on other forums, I'll pay attention this time

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Well, as I said ...
    Post the form they are filling out,
    and post the script you wrote that only sends the email address.

    This sounds like it should be a mobile online app, where you can
    punch a button and get an instant list of details for ALL forms
    that were submitted. Perhaps there doesn't need to be an email at all ...
    or in the least, you are notified to check the data.

    One problems with emails ... let's say a prospect creates an appointment
    and your employee fills out the form, and you get an email with the details.
    An hour later, the prospect calls and says "something just came up and I
    need to reschedule". What then? So your employee fills it out again and you
    get another email? What if you didn't see the 2nd email?

    Wouldn't it be much better if the employee entered the appointment into a
    database, and they update it for any changes? At any time, you click an icon on
    your iphone, and instantly you access the database of appointments. Scroll
    through, sort by date, time, filter results. Even get an instant SMS message
    to remind you of upcoming appointments or changes.

    I always think email is a bad idea for informational applications.
    But it can be done. It's your company ... you can do whatever you want.

  • #11
    New to the CF scene
    Join Date
    May 2009
    Location
    Miami, FL
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thank you

    You open my eyes, I will start working on something more practical with your ideas, thank you


  •  

    Posting Permissions

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