Appnitro Software Forums » MachForm

Customising Checkbox Value

(15 posts)
  • Started 2 years ago by philwareham
  • Latest reply from yuniar

  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 2 years ago #
  2. 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.

    Posted 2 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 2 years ago #
  4. 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.

    Posted 2 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 2 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 1 year 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 1 year ago #
  8. 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.

    Posted 1 year 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 1 year ago #
  10. 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 1 year ago #
  11. 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 1 year ago #
  12. So if someone select the checkbox, they will be redirected immediately to that URL? Abandoning your current form?

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

    Posted 1 year ago #
  14. 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 1 year ago #
  15. much better idea! hehehe

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.