PHP Dynamic Form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #16
    Hi ezb,

    you do this by building code block which run based on which post values are set

    so :

    [PHP]<?php
    if (isset($_POST['first_select']) and $_POST['first_select'] <> "default value" and !isset($_POST['second_select']) ) {
    //
    do the code to build the second select
    //
    }
    elseif(isset($_ POST['first_select']) and $_POST['first_select'] <> "default value" and isset($_POST['second_select']) and $_POST['second_select'] <> "default value" ) {
    //
    do the code to save the data to the database
    //
    }
    ?>[/PHP]

    does that help ?

    Purple

    Comment

    • ezb
      New Member
      • Jul 2007
      • 9

      #17
      sorry about this but the above doesnt make much snece to me.

      I've got the java script working but as I though, when I select an option it basicly refreshes the form, taking all the items back to the default, was wondering if theres a way to get the same result but keeping what the user has selected in the form, purhaps taking the selected into a variable and using them as default when the form submits somehow?

      Comment

      • Purple
        Recognized Expert Contributor
        • May 2007
        • 404

        #18
        Hi,

        as with all of these things, there are a number of ways to achieve this..

        simplest is prob using sessions so :

        [PHP]<?php
        session_start() ; // this needs to be executed before anything is sent to the browser - including any white space
        if (!isset$_SESSIO N['form_vars']) session_registe r('form_vars');
        if(!empty($_POS T['variable']) $_SESSION['form_vars']['variable'] = $_POST['variable']; // this needs to be done for all vars on the form
        else $_SESSION['form_vars']['variable'] = null;
        // now in the form we can set the field values to $_SESSION['form_vars']
        ['variable'] and this will be maintained across submissions of the form.
        //*
        //* build the form here
        //*
        // when its processed you need to do the following to clear the variables:
        unset($_SESSION['form_vars'][);
        // its also good practise to tidy the session record too using:
        session_destroy (); // but only after you have saved your values...

        ?>[/PHP]

        Does that help ?

        Questions ?

        Comment

        Working...