(solved) adding cancel button (history.back) to submit buttn

?
Guest 02 Sep, 2011
hi all,

I would like to add a cancel button to the right of the submit button

editing the submit button element (input_submit.ctp) like this
find:
<input type="button" name="submit_{n}_input_name" id="submit_{n}_input_id" value="<?php echo $element_params['input_value']; ?>" />

and adjust for:
<input type="button" name="submit_{n}_input_name" id="submit_{n}_input_id" value="<?php echo $element_params['input_value']; ?>" />
<input type="button" name="cancel" onclick="history.back()" value="<?php echo JText::_('Cancel'); ?>" />

however is not sufficient as all it does it make the cancel button show in preview tab

could somebody pls provide a hint on what to edit to make it show on user side as well ?
GreyHead 03 Sep, 2011
Hi GabrielaH,

I think you need to edit the administrator/components/com_chronoforms/helpers/html_helper.php file. Look for the case 'submit': block around line 162 (in the RC2.0 Joomla! 1.6 release).

You might also add a Reset option at the same time?

Bob
?
Guest 03 Sep, 2011
thanks Bob!🙂

yes a reset option would be neat to have as well

so far I'm failing though in getting that snippet adjusted - apart from generating errors or breaking the site completely that is...
GreyHead 17 Sep, 2011
Hi GabrielaH,

I think I've got this working OK. There's one more file that needs to be changed.

administrator/components/com_chronoforms/form_elements/input_submit.ctp
<div class="dragable" id="input_submit">Submit Button</div>
<div class="element_code" id="input_submit_element">
	<input type="button" name="submit_{n}_input_name" id="submit_{n}_input_id" value="<?php echo $element_params['input_value']; ?>" />
	<input type="hidden" name="chronofield[{n}][input_submit_{n}_input_name]" id="input_submit_{n}_input_name" value="<?php echo $element_params['input_name']; ?>" />
    <input type="hidden" name="chronofield[{n}][input_submit_{n}_input_id]" id="input_submit_{n}_input_id" value="<?php echo $element_params['input_id']; ?>" />
    <input type="hidden" name="chronofield[{n}][input_submit_{n}_input_value]" id="input_submit_{n}_input_value" value="<?php echo $element_params['input_value']; ?>" />
    <input type="hidden" name="chronofield[{n}][input_submit_{n}_input_class]" id="input_submit_{n}_input_class" value="<?php echo $element_params['input_class']; ?>" />
    <input type="hidden" id="chronofield_id_{n}" name="chronofield_id" value="{n}" />
    <input type="hidden" name="chronofield[{n}][input_submit_{n}_add_cancel]" id="input_submit_{n}_add_cancel" value="<?php echo $element_params['add_cancel']; ?>" />
<input type="hidden" name="chronofield[{n}][input_submit_{n}_add_reset]" id="input_submit_{n}_add_reset" value="<?php echo $element_params['add_reset']; ?>" />
    <input type="hidden" name="chronofield[{n}][tag]" value="input" />
    <input type="hidden" name="chronofield[{n}][type]" value="submit" />
</div>
<div class="element_config" id="input_submit_element_config">
<?php 
echo $HtmlHelper->input('input_submit_{n}_input_name_config', 
	array(
		'type' => 'text', 
		'label' => 'Name', 
		'class' => 'small_input', 
		'value' => ''
	)
);
echo $HtmlHelper->input('input_submit_{n}_input_id_config', 
	array(
		'type' => 'text', 
		'label' => 'ID', 
		'class' => 'small_input', 
		'value' => ''
	)
);
echo $HtmlHelper->input('input_submit_{n}_input_value_config', 
	array(
		'type' => 'text', 
		'label' => 'Text', 
		'class' => 'small_input', 
		'value' => ''
	)
);
echo $HtmlHelper->input('input_submit_{n}_input_class_config', 
	array(
		'type' => 'text', 
		'label' => 'Class', 
		'class' => 'small_input', 
		'value' => ''
	)
);
echo $HtmlHelper->input('input_submit_{n}_add_cancel_config', 
	array(
		'type' => 'checkbox', 
		'label' => 'Add Cancel button', 
		'value' => '1', 
		'rule' => "bool"
	)
);
echo $HtmlHelper->input('input_submit_{n}_add_reset_config', 
	array(
		'type' => 'checkbox', 
		'label' => 'Add Reset button', 
		'value' => '1', 
		'rule' => "bool"
	)
);
?>
</div>

administrator/components/com_chronoforms/form_elements/input_submit.php
<?php
/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @license		GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
**/

class ChronoFormsInputSubmit
{
	function load($clear)
	{
		if ( $clear ) {
			$element_params = array(
				'input_name' => 'input_submit_{n}',
				'input_id' => '',
				'input_class' => '',
				'input_value' => 'Submit',
				'add_cancel' => 1,
				'add_reset' => 1
			);
		}
		return array('element_params' => $element_params);
	}
}
?>

administrator/components/com_chronoforms/helpers/htmlhelper.php around line 165
			case 'submit':
				unset($fieldoptions['value']);
				$output .= '<input';
				foreach($tag as $k => $v){
					if ( in_array($k, array('add_cancel', 'add_reset')) ) {
						continue;
					}
					$output .= ' '.$k.'="'.$v.'"';
				}
				$output .= ' />'."\n";
				if ( $tag['add_cancel'] ) {
					$output .= " <input type='button' name='cancel' onclick='history.back()' value='".JText::_('Cancel')."' />";
				}
				if ( $tag['add_reset'] ) {
					$output .= " <input type='reset' name='reset' value='".JText::_('Reset')."' />";
				}
				unset($fieldoptions['label']);
				break;

administrator/components/com_chronoforms/admin.chronoforms.php around line 957
		case 'submit':
			$formcontent_item_array['name']  = $formdata_element[$field_header.'_input_name'];
			$formcontent_item_array['id']    = $formdata_element[$field_header.'_input_id'];
			$formcontent_item_array['class'] = $formdata_element[$field_header.'_input_class'];
			$formcontent_item_array['value'] = $formdata_element[$field_header.'_input_value'];
			// :: HACK ::
			$formcontent_item_array['add_reset'] = $formdata_element[$field_header.'_add_reset'];
			$formcontent_item_array['add_cancel'] = $formdata_element[$field_header.'_add_cancel'];
			// :: END HACK ::
			$formcontent_item_array['type']  = $formdata_element['type'];
			break;

This adds checkboxes in the Submit Button Configuration to add Cancel and Reset buttons alongside the Submit button. As written it doesn't add ids or classes but could be extended if needed.

Bob
?
Guest 06 Oct, 2011
thanks bunches ! thats working like a charm!
pcheng 09 Dec, 2011
Bob,

I tried changing the files you specified with the values that you said but now all my forms are empty. Nothing shows up.

Did I make a mistake somewhere? Do I need to change anything else?

Does the change not work with the latest version of Chronoforms?

Thanks,

Pericles

EDIT. I had to reinstall chronoforms to get it working. The problem occurs when I try to change the html_helper.php. Even if I copy the original text in it the forms show blank pages. It might have something to do with edit rights. I will check my chmod but if you have any suggestions please let me know.
GreyHead 09 Dec, 2011
Hi pcheng,

It sounds as though there may be a typo somewhere in the changes you are making to the Html_helper.php file :-)

If you set Error Reporting to Maximum in the Site Global Configuration then you may see a more helpful error message.

Bob

PS This hack has been running on my test site for a few months now so it does seem to work OK.
pcheng 09 Dec, 2011
I found the error and you are not going to believe what it was.

The FTP mode was on ASCII and not Binary which caused the file to transfer wrongly. Even though I could see it it lost the CR codes.

Works now. Thanks,

Pericles
GreyHead 10 Dec, 2011
Hi Pericles,

Well found - I wouldn't have thought of that.

Bob
This topic is locked and no more replies can be posted.