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
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question What makes a site go to the page where a form is being submitted?

    Hi,

    When a form is submitted what is it that makes the user visit the page the form is submitted to?

    I have a form that doesn't do this when I want it to, because of this currently the form only works when its on the page its submitted to.

    For example (its a search function I'm doing) if the site is on the search page it works fine but when its on a different page it tries to perform the function on that page instead. So it would show:
    itempage.php?search=searchterm
    instead of
    search.php?search=searchterm

    Any help much appreciated!
    Thanks

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Form action value is the where form does it's functions. If you have a form that you want to search on the same page you set your form to, you should use probably use some predefined variable like $_SERVER['php_self']

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,092
    Thanks
    2
    Thanked 322 Times in 314 Posts
    My guess is that your <form... tag does not have an action="..." parameter at all and is submitting back to the current page instead of your search.php page.

    You would need to post your code to get specific help with it.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    My guess is that your <form... tag does not have an action="..." parameter at all and is submitting back to the current page instead of your search.php page.

    You would need to post your code to get specific help with it.
    I'm not that silly

    The form itself:
    PHP Code:
    $menu[] = '<p class="mainlink">Search';
    $menu[] = '<form submit="search.php">';
    $menu[] = '<input type="text" name="search" size="12" />&nbsp;';
    $menu[] = '<input type="submit" name="submit" value="GO!" />';
    $menu[] = '</form></p>'
    The search.php page:
    PHP Code:
    $search $_GET['search'];
    if (
    $search != "") {
         
    $sql 'SELECT * FROM item WHERE description LIKE "%' .$search'%" OR item_name LIKE "%' .$search'%"OR keywords LIKE "%' .$search'%"';
    }
    else{
         
    $sql 'SELECT * FROM item';
    }
    ... 

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh yeah, I tried what matak suggested and it didn't make a difference.

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    The <form> tag does not have an attribute named "submit".
    PHP Code:
    <form submit="search.php"
    it should be "action"
    PHP Code:
    <form action="search.php"

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,092
    Thanks
    2
    Thanked 322 Times in 314 Posts
    I'm not that silly
    Perhaps you should slow down and read my post and matak's post (he mentions the action parameter too.) The following line in your code has no meaning -
    PHP Code:
    $menu[] = '<form submit="search.php">'
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Also i'm not even sure how your gonna get this variable

    PHP Code:
    $search $_GET['search']; 
    When you didn't set the method your form works

    Code:
    <form action="search.php" method="GET">
    I would recommend you that you use post instead of get for this example

    PHP Code:
    $search $_POST['search']; 
    and form
    Code:
    <form action="search.php" method="POST">

  • #9
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,092
    Thanks
    2
    Thanked 322 Times in 314 Posts
    Actually, the default method is GET if one is not specified.

    I was going to post the link to the w3schools html form section, but their web page is not responding at the current time and the OP should be able to lookup the proper syntax for a form. Got enough of it to post - http://w3schools.com/html/html_forms.asp
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #10
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Actually, the default method is GET if one is not specified.
    oh, ok.

    Yes, i tried to reach w3schools yesterday, and i couldn't see their pages. Who knows, maybe their redesigning.

    Btw this code works..

    PHP Code:
    <form action="">
    <input type="text" name="search">
    <input type="submit">
    </form>

    <?php

    @$search $_GET['search'];

    if (
    $search != ""){
        echo 
    $search;
    }
    else {
        echo 
    "Please search something";
    }
    ?>

  • #11
    New Coder
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh Gawd!

    I did not see that!

    This is why fresh eyes spot somethings that others mightn't!

    Thanks guys!


  •  

    Posting Permissions

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