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

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 3

How do I replace form field result with text?


  1. MvdL79
    Member

    Okay I upgraded a single license of Machform v3.2 to see if it's really an improvement. And to be honest, I am liking it so far.

    However I need somehting done, which could be done with Machform v2, so I am hoping this also can be done with v3.2. Hopefully someone can explain the following to me (and what I need to add and / or change in the current code).

    I have a pull-down field on my form, with the following options:

    Option #1
    Option #2
    Option #3
    Option #4

    If I select 'Option #1' from the pull-down, it should replace this with the following text "This is the example text for option #1." in the email which will be send. When selecting a different option, like 'Option #3' it should replace this text with "This is a different example of text being displayed for option #3.".

    I will also need this text replacement option for the radio button (multiple choice) options.

    This was possible with Machform v2, so I am hoping this will also be available for Machform v3. So I am hoping Yuniar can tell me what to change or add in the current code.

    Also if everything goes well and works without problems, we will be upgrading our licence to an unlimited license once again.

    Thanks.

    Posted 12 years ago #
  2. MvdL79
    Member

    * bump *

    Posted 12 years ago #
  3. yuniar

    This still possible. You will need to edit your "includes/helper-functions.php" file.
    Let say your form is having id number 7, search around line 371 for this code:

    foreach ($entry_details as $data){

    right below that code, add this code:

    if($form_id == 7 && $data['element_type'] == 'select'){
        switch ($data['value']) {
            case 'Option #1': $data['value'] = 'This is the example text for option #1';break;
            case 'Option #2': $data['value'] = 'This is the example text for option #2';break;
            case 'Option #3': $data['value'] = 'This is the example text for option #3';break;
        }
    }

    that should do it.


    MachForm Founder

    Posted 12 years ago #
  4. MvdL79
    Member

    This is for the multiple choice (radio buttons), right?

    And would you also be so kind to give me an example with the 'OR' command for multiple form ID's?
    Less code is always better, right?

    Posted 12 years ago #
  5. yuniar

    The above is actually for dropdown field. For multiple choice, the first line should be using this one:

    if($form_id == 7 && $data['element_type'] == 'radio'){

    MachForm Founder

    Posted 12 years ago #
  6. yuniar

    If you need to apply the code for multiple forms, I suggest to simply put another block as above with different id number.
    Using 'OR' on this particular case might cause some problem when your forms has similar dropdown/multiple choice options.


    MachForm Founder

    Posted 12 years ago #
  7. MvdL79
    Member

    Thanks for the replies Yuniar. Highly appreciated!

    Okay, I always thought less code was better. ;)

    Posted 12 years ago #
  8. MvdL79
    Member

    Okay I tried it today, however for some reason it doesn't replace anything, but it justs posts the (original) text behind the radio button.

    I did the following:

    if($form_id == 1 && $data['element_type'] == 'radio'){
    switch ($data['value']) {
    case 'Yes, for sure': $data['value'] = 'This should give a big thank you.<br><br>';break;
    case 'No, thank you': $data['value'] = 'Another fine example for you...<br><br>';break;
    case 'This does not work': $data['value'] = 'Arrrrrrggggggggggghhhhh....<br><br>';break;
    }
    }

    For some reason this doesn't replace text at all. If I select the radio button 'This does not work' it will parse 'This does not work' in the emailed form, instead of 'Arrrrrrggggggggggghhhhh'.

    I added the code below line 371 like you mentioned. Any ideas?

    Posted 12 years ago #
  9. yuniar

    Can you send me the modified file and let me know the URL to your form please? I'll check it.
    http://www.appnitro.com/contact


    MachForm Founder

    Posted 12 years ago #
  10. MvdL79
    Member

    Mailed.

    Posted 12 years ago #
  11. MvdL79
    Member

    Emailed again...?

    Posted 12 years ago #
  12. MvdL79
    Member

    By the way; in the old version of Machform (v2.3) this was done completely different?

    if($data['element_type'] == 'radio'){
    	if($form_id == 3){
    	if($data['element_id'] == 8){
    
    	if(trim($data['value']) == "Option #1"){
    	$entry_details[$i]['value'] = "Swap option #1 with this example #1";
    
    	}elseif(trim($data['value']) == "Option #2"){
    	$entry_details[$i]['value'] = "Swap option #1 with this example #2";
    
    	}elseif(trim($data['value']) == "Option #3"){
    	$entry_details[$i]['value'] = "Swap option #1 with this example #3";
    
    	}elseif(trim($data['value']) == "Option #4"){
    	$entry_details[$i]['value'] = "Swap option #1 with this example #4";
    
    	}elseif(trim($data['value']) == "Option #5"){
    	$entry_details[$i]['value'] = "Swap option #1 with this example #5";
    			}
    			}
    	$template_values[$i] = $entry_details[$i]['value'];
    	}
    }

    Or something like that....

    Posted 12 years ago #

RSS feed for this topic

Reply