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

Customising Checkbox Value


  1. philwareham
    Member

    Hi there,
    On one of my forms, there is a single checkbox (for reference it is element_11_1 on form_1) that allows form senders to opt in to a newsletter. At the moment the label for that checkbox is a long disclaimer text (which I filled in on the choices field when creating the form), and that whole text is then included in the database if the user checks the box.
    Is there a way I can customise the value of the checkbox so it simply states 'yes' in the database, not the whole label text?
    Thanks,
    Phil

    Posted 15 years ago #
  2. yuniar

    Do you mean to show 'Yes' when you view it through view_entry.php ?

    If so, edit your includes/entry-functions.php file.
    Search around line 375, you'll find this code:

    if(!empty($checkbox_content)){
    	$entry_details[$i]['value'] = rtrim($checkbox_content,'<br />');
    }


    Replace it with this one:

    if($form_id == 1 && $element_id == 11){
    	$entry_details[$i]['value'] = '<img src="'.$options['machform_path'].'images/icons/checkbox_16.gif" align="absmiddle" /> Yes';
    }else{
    	$entry_details[$i]['value'] = rtrim($checkbox_content,'<br />');
    }


    That should do it.


    MachForm Founder

    Posted 15 years ago #
  3. philwareham
    Member

    Hi yuniar,

    Thanks for that, but I think my original message was a bit unclear... Basically for a field with just a single checkbox, I want the entries database column heading to use the description text not the label text. Can this be done?

    Also, do you think it would be a good idea to have a separate forum section for machform hacks so people can find them easily? I'm sure some will be interested in things like, for example, the option to have spaces and dashes in international telephone numbers, which you provided in an earlier post.

    Cheers, Phil

    Posted 15 years ago #
  4. yuniar

    Oh.. I see.

    Try this, edit your manage_entries.php, search around line 180 -183:

    foreach ($this_checkbox_options as $option_id=>$option){
    	$column_name_lookup['element_'.$row['element_id'].'_'.$option_id] = $option;
    	$column_type_lookup['element_'.$row['element_id'].'_'.$option_id] = $row['element_type'];
    }


    replace it with this one:

    foreach ($this_checkbox_options as $option_id=>$option){
    	if($form_id == 1 && $row['element_id'] == 11){
    		$column_name_lookup['element_'.$row['element_id'].'_'.$option_id] = 'Yes';
    	}else{
    		$column_name_lookup['element_'.$row['element_id'].'_'.$option_id] = $option;
    	}
    	$column_type_lookup['element_'.$row['element_id'].'_'.$option_id] = $row['element_type'];
    }


    let me know how it goes.


    MachForm Founder

    Posted 15 years ago #
  5. philwareham
    Member

    That works beautifully (I just amended the 'Yes' in row 3 to 'Receive Newsletters?' though), thanks for the continued support yuniar.
    This software is great.

    Posted 15 years ago #
  6. vancoovur
    Member

    This one doesn't work for me. I made the changes to manage_entries.php as per your instructions above, created a test form with a single check box and viewed the results within MachForm and by exporting the data to Excel. Both retained the 'First Option' field description rather than replacing with 'Yes'. Has something changed since this was posted 9 months ago?
    Thanks Yuniar

    Posted 15 years ago #
  7. vancoovur
    Member

    I retract the above post as it *did* work but...
    I have a form with a number of single checkboxes with no field label and the 'choice' text is 'I subscribe to your magazine'. If the box is checked I need the exported data (Excel document) to contain a column header that reads 'I subscribe to your magazine' and a 'Yes' in the corresponding data field. If the checkbox is not selected the data field within the 'I subscribe to your magazine' column will be empty. Can this be done or is there a better way to accomplish this?

    Posted 15 years ago #
  8. redityo

    Hi,

    Try to edit your "export_entries.php", around line 304~307 you'll find these code :

    if(!empty($row[$column_name])){
    	$form_data[$i][$j]  			= $column_label[$j];
    }

    replace with this one

    if(!empty($row[$column_name])){
    	if ($column_name == 'element_1_1' && $form_id == 11)
    		$form_data[$i][$j]  			= 'Yes';
    	else
    		$form_data[$i][$j]  			= $column_label[$j];
    }

    when you export the entries, you can see that "element_1" check box will have column header name "I subscribe..." with value "Yes" if checked.
    Don't forget to make sure you have adjust the element id and form id with yours.


    MachForm Support

    Posted 15 years ago #
  9. vancoovur
    Member

    Thanks for your quick reply. It's always appreciated!
    I would like to make this modification global, not just for a single form. In other words, I would like any check boxes that are selected within a form to enter the 'Yes' value. Is this possible?

    Posted 15 years ago #
  10. teamwebb2008
    Member

    I tried to change my checkbox on Yes to go something like this:

    if($form_id == 2 && $element_id == 104){
    $entry_details[$i]['value'] = '<img src="'.$options['http://www.tfscnc.org/machform/view.php?id=9'].'images/icons/checkbox_16.gif" align="absmiddle" /> Yes';
    }else{
    $entry_details[$i]['value'] = rtrim($checkbox_content,'
    ');
    }

    But nothing happened. Did I miss something somewhere?

    Posted 15 years ago #
  11. teamwebb2008
    Member

    What I am trying to do is, if someone selects TFSC checkbox, they will go to that form .....id_9, if not, they can continue the app.

    Posted 15 years ago #
  12. yuniar

    So if someone select the checkbox, they will be redirected immediately to that URL? Abandoning your current form?


    MachForm Founder

    Posted 15 years ago #
  13. teamwebb2008
    Member

    Correct. This avoids them filling out a form not needed. They should be directed to the form requesting that service. (Also a MachForm)

    Posted 15 years ago #
  14. teamwebb2008
    Member

    I found a way around it. Since there is no reason to keep this information in the database for the current form, I used idea from another of your posts and went with the following in a section break: Click here for Team Factory Bridge Program Membership Application

    It works like a charm!! Thanks anyway. If I keep this up, can I graduate from your school?? :)

    Posted 15 years ago #
  15. yuniar

    much better idea! hehehe


    MachForm Founder

    Posted 15 years ago #

RSS feed for this topic

Reply