www.webdeveloper.com
Results 1 to 4 of 4

Thread: Splitting up a .PHP form

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    23

    Splitting up a .PHP form

    I'm working with a .PHP file which holds a form.

    this form allows the user to choose:
    -Categories
    -SubCategories
    -A Price Range

    or input:
    - Search Keywords
    - Search Location

    when the user presses the submit button,
    content displayed from another .PHP file is updated.


    Is there a way for me to split a form like this, up into different php files for each function of the form. For example, one .PHP file for categories, subcategories, search keywords, etc...




    <form>

    <select name="category">
    <option> </option>
    </select>

    <select name="subcategories">
    <option></option>
    </select>

    <select name="priceRange">
    <option></option>
    </select>


    <label class="keywordSearch">
    <input> </input>
    </label>


    <label class="locationSearch">
    <input></input>
    </label>


    <input type='button'>Search</input>

    </form>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    One way would be to have it call one file, then use some branching logic in that file to include the file you want to process that type of request.
    PHP Code:
    if(!empty($_POST['some_field'])) {
      include 
    'some_file.php';
    }
    elseif(!empty(
    $_POST['some_other_field'])) {
      include 
    'some_other_file.php';

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2012
    Posts
    14
    There are a few options. NogDog's way is one. You can jump to different functions in the same file.
    PHP Code:
    $choice = isset($_POST['some_field']) ? $_POST['some_field'] : '';
    if(
    $choice == 'c')
      
    categories()';
    elseif($choice == '
    s')
      subcategories();
    ...
    else die('
    Stop trying to call my PHP file directly.') 
    You could use switch/case instead of if.

  4. #4
    Join Date
    Dec 2011
    Posts
    23

    thank you very much

    thats very useful

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles