This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

How can I set PHP variables in forms?


  1. nilsmierzynski
    Member

    I would love to load the form with different option selection depending from where I open the form. For example:

    berlin.php with link to form.php?id=1&city=berlin ===> form.php: <SELECT><OPTION value="Berlin" selected>

    I know the PHP code, but I am not sure where I have to place the code to get it just in the form (ID) I want it to be.

    Thank you all
    Nils

    Posted 17 years ago #
  2. redityo

    Hi,

    What for form.php is ? do you embed machform code to "form.php" ?
    however you need to edit "view-functions.php", Let say you have form with id = '1' and drop down with element id = '2'. For example drop down values are :

    -one
    -two
    -three

    around line 637 you will find :

    $option_markup .= "<option value=\"{$option->id}\" {$selected}>{$option->option}</option>\n";

    try to replace with

    if ((trim($_GET['city']) == $option->option) && ($element->id == '2') &&
    ($_GET['id'] == '1')) {
       $selected = 'selected="selected"';
    }

    MachForm Support

    Posted 17 years ago #
  3. nilsmierzynski
    Member

    Hi redityo!

    Sorry I was a bit imprecise in this point:

    The iframe-form should been loaded with this url (on my opinion?!?):
    /machform/view.php?id=2&element_17=10

    form id=2
    drop-down select id=element_17
    drop-down select value= 10 (for example)

    Because I do not have the variable "city" I changed it to this,
    but without success! The result was that no option were displayed.
    I must be wrong somewhere...

    if ((trim($_GET['element_17']) == $option->option) && ($element->id == 'element_17') && ($_GET['id'] == '2')) {
    	$selected = 'selected="selected"';
    }

    Hope you can help me with that...
    Thank you!
    Nils

    Posted 17 years ago #
  4. redityo

    Hi Nils,

    Try with this one

    if ((trim($_GET['element_17']) == $option->option) &&
    ($element->id == '17') &&
    ($_GET['id'] == '2')) {
    	$selected = 'selected="selected"';
    }

    I see that you wrong put the condition it should $element->id == '17' not $element->id == 'element_17'


    MachForm Support

    Posted 17 years ago #
  5. nilsmierzynski
    Member

    Hi redityo!

    Sorry... no it did not wor here...

    when I open the form (which is actually an iframe of another page) directly like:
    /machform/view.php?id=2&element_17=10

    there are no options available in the drop-down element.

    Something must still be wrong.
    Thank you for your effort and brilliant support.
    Best wishes, Nils

    Posted 17 years ago #
  6. redityo

    Hi nils,

    what is your drop down value ? however could I have your form URL ?


    MachForm Support

    Posted 17 years ago #
  7. nilsmierzynski
    Member

    Hi redityo!

    Sorry for the delay...
    Here is the form URL: http://www. h o e f f n e r .de/machform/embed.php?id=2

    I want to set one of this options "selected" via PHP variable in this drop-down selection:

    <select name="element_17" id="element_17" class="element select large">
    <option selected="selected" value=""/>
    <option value="2">Berlin-Marzahn</option>
    <option value="3">Berlin-Waltersdorf (Schönefeld)</option>
    <option value="4">Berlin-Wedding Pankstraße (Mitte)</option>
    <option value="5">Chemnitz-Röhrsdorf</option>
    <option value="6">Cottbus-Willmersdorf</option>
    <option value="7">Dresden-Altfranken</option>
    <option value="8">Dresden-Elbepark</option>
    <option value="9">Erfurt-Waltersleben</option>
    <option value="10">Frankfurt-Gründau</option>
    <option value="11">Fürth</option>
    <option value="12">Halle-Peißen</option>
    <option value="21">Hamburg-Barsbüttel</option>
    <option value="13">Leipzig-Günthersdorf</option>
    <option value="14">Leipzig-Taucha</option>
    <option value="15">Magdeburg-Langenweddingen</option>
    <option value="16">Magdeburg-Pfahlberg</option>
    <option value="17">Mannheim-Schwetzingen</option>
    <option value="18">München-Freiham</option>
    <option value="19">Rostock-Bentwisch</option>
    </select>

    Hope that will help you to advice me.
    Thank you, Nils

    Posted 17 years ago #
  8. nilsmierzynski
    Member

    Did you forget to answer my post?
    Please give me your advice.

    Thank you.
    Nils

    Posted 17 years ago #
  9. yuniar

    Oops..sorry. It seems your post was buried. I've notified redityo.
    He should reply soon with some solution.


    MachForm Founder

    Posted 17 years ago #
  10. redityo

    Hi Nils,

    Sorry for the delays, I think I give you wrong instruction, it's my bad!. it's not to replace but it suppose to add the code.
    However, you want to select the "drop down" field based on "select" ID, let say you have this url :

    http://www.hoeffner.de/machform/embed.php?id=2&element_17=2

    You already see this code around line 637:

    $option_markup .= "<option value=\"{$option->id}\" {$selected}>{$option->option}</option>\n";

    please add these code exactly above that line :

    if ((trim($_GET['element_17']) == $option->id) && ($element->id == '17') && ($_GET['id'] == '2')) {
    	$selected = 'selected="selected"';
    }

    it should select "Berlin-Marzahn" ...


    MachForm Support

    Posted 17 years ago #
  11. nilsmierzynski
    Member

    Phantastic! Works great!
    Thank you very much!

    Happy Holidays.
    Nils

    Posted 17 years ago #

RSS feed for this topic

Reply