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

Define own Field Type


  1. juehec
    Member

    Is there a possibilty to define my own Field Type like the Address. If it is possible how can i do this.

    Thanks Juergen

    Posted 16 years ago #
  2. yuniar

    I'm afraid there is no easy way to do this.
    You will need to modify pretty much of the front end and backend code to do this.

    I'm just wondering, what field type do you want to add?


    MachForm Founder

    Posted 16 years ago #
  3. juehec
    Member

    Hi,

    i need no new field type, but i need for example a adress combo with the field
    address, street, street2, zip, city, country, state and sometimes i need the same without state.

    Juergen

    Posted 16 years ago #
  4. yuniar

    Hmm.. you can always modify includes/view-functions.php file for every display aspects.

    In your case, you will need to modify display_address() function to dynamically show/hide the state based on the form id.

    Ok, around line 1302, search for this block:

    <div class="right">
    	<input id="element_{$element->id}_4" name="element_{$element->id}_4" class="element text medium" value="{$element->populated_value['element_'.$element->id.'_4']['default_value']}" type="text">
    	<label for="element_{$element->id}_4">State / Province / Region</label>
    </div>


    Remove that block, and replace it with:

    {$state_markup}


    Now.. few lines above, around line 1283, you will find this line:

    $element_markup = <<<EOT

    Above that line add this block:

    $state_markup =<<<EOT
    <div class="right">
    	<input id="element_{$element->id}_4" name="element_{$element->id}_4" class="element text medium" value="{$element->populated_value['element_'.$element->id.'_4']['default_value']}" type="text">
    	<label for="element_{$element->id}_4">State / Province / Region</label>
    </div>
    EOT;
    
    $state_disabled = array(YOUR_FORM_ID);
    
    if(in_array($_REQUEST['id'],$state_disabled)){
    	$state_markup = '';
    }


    And you are done. Don't forget the replace YOUR_FORM_ID with your actual form id number. Like:
    $state_disabled = array(2);

    Or if you want to disable the state for few forms, you can use a comma, like this:
    $state_disabled = array(2,3,4);

    If those above sounds too difficult. Let me know.
    I'll help you with the modification.


    MachForm Founder

    Posted 16 years ago #
  5. villah
    Member

    Hi Yuniar,
    I've tried this and it works well... but... if the address block is required in the form and you have hidden the State field, for instance, you won't be able to submit the form since it will keep telling you that you need to fill out the required fields.. but since you can't see the state field..

    Any ideas?

    Thanks!
    Hans

    BTW: great piece of software!

    Posted 16 years ago #
  6. yuniar

    Hi Hans,

    Try this, edit your includes/post-functions.php file.
    Around line 399 you will find this code:

    }elseif ('address' == $element_type){ //Address

    Few lines below that code, on line 420, you will find this code:

    $rules[$element_name_4]['required'] = true;

    remove this line and the state checking would be removed.

    Let me know if you have trouble.


    MachForm Founder

    Posted 16 years ago #

RSS feed for this topic

Reply