Using HTML::FormFu, how do you change a field value *after* processing so that it appears modified in Template Toolkit? - perl

For example, if I process a form:
my $form_input = { input_data => '123' };
$form->process($form_input);
Then I want to alter the value of 'input_data':
my $clearme = $form->get_field('input_data');
$clearme->value("546"); # doesn't seem to work
..Before pushing the form object to TT:
template 'index' => { form => $form }; # using Dancer
'input_data' seems to retain it's original value (123). Any hints on what I'm doing wrong, or what I should be doing?
Thanks

After looking at the documentation and doing some testing, I think you want
$form->add_valid(input_data => '546');

Related

HTML::FormHandler field validation based on other field's check'd state

I am developing a Perl/Catalyst web app using HTML::FormHandler for forms.
I am trying to do a conditional validation on a field if a checkbox is checked.
The code below is from a Role I created for my form to use.
has_field 'autosys_jobs.schedule.has_run_day_of_month' => ( type=>'Boolean');
has_field 'autosys_jobs.schedule.run_day_of_month' => ( type => 'PosInteger');
#Validation function for 'autosys_jobs.schedule.run_day_of_month'
sub validate_autosys_jobs_schedule_run_day_of_month {
my ( $self, $field ) = #_;
if( $self->field('autosys_jobs.schedule.has_run_day_of_month')->value ) {
#validate 'autosys_jobs.schedule.run_day_of_month'
}
}
The problem I'm having is that $self->field('autosys_jobs.schedule.has_run_day_of_month')->value
for the boolean field always returns 0 even if it's checked.
Any ideas on what I'm doing wrong?
After digging deeper into the HTML::FormHandler documentation I was able to figure out my mistake.
The field autosys_jobs.schedule is a compound field(forgot to mention that)
has_field 'autosys_jobs.schedule' => ( type => 'Compound');
in order to access the field of interest I had to use the following in my validate sub:
$self->field('autosys_jobs.0.schedule.has_run_day_of_month')->value
Thanks all

phpseclib createKey() using own primes

Is it possible to generate private and public key in PKCS#1 format using phpseclib and my own primes? I mean I already have p and q and I want to generate both keys. I am trying to do something like this:
$p = new Math_BigInteger(...);
$q = new Math_BigInteger(...);
$custom_primes = serialize(array('primes'=>array(1=>$p,2=>$q)));
extract($rsa->createKey(512,10,$custom_primes));
But this gives me the fatal error:
Fatal error: Call to a member function divide() on a non-object in /volume1/web/phpseclib/Crypt/RSA.php on line 705
I checked this and it is trying to divide:
list($temp) = $lcm['top']->divide($lcm['bottom']);
Obviously I am not setting up lcm in my $custom_primes structure as I only have my two primes. So the question is: is it possible at all in phpseclib?
It looks like you're trying to use phpseclib's partial key functionality to achieve this. Problem is that expects more than just primes. See this, for example:
return array(
'privatekey' => '',
'publickey' => '',
'partialkey' => serialize(array(
'primes' => $primes,
'coefficients' => $coefficients,
'lcm' => $lcm,
'exponents' => $exponents
))
);
$lcm is defined, initially, like this:
$lcm = array(
'top' => $this->one->copy(),
'bottom' => false
);
So maybe try doing that as well. You can probably strip out all of the calculation functions
from phpseclib, do them yourself and then pass $partial into phpseclib and let it generate a key in whatever format you want it generated in.

TYPO3: Use t3lib_TCEforms in frontend plugin

I would like to use as much standard TYPO3 as possible to create a form to edit single records from tx_mytable.
In pi1 i load the tca for the table:
t3lib_div::loadTCA('tx_mytable');
Now I would like to use standard functions to create my form elements more or less like it is done in the backend...
I found this for the front end but cannot find any working examples:
t3lib_TCEforms_fe.php (that extends the normal t3lib_TCEforms)
Is this the right way to go or is there a better way?
I got something working but not really that nice code in the frontend
Here is a link that telss that TCA is not enough but two new entries in the array is needed
http://www.martin-helmich.de/?p=15
It is itemFormElName and itemFormElValue
// include tceforms_fe (place outside class where pipase is included)
require_once(PATH_t3lib.'class.t3lib_tceforms_fe.php');
// load TCA for table in frontend
t3lib_div::loadTCA('tx_ogcrmdb_tasks');
// init tceforms
$this->tceforms = t3lib_div::makeInstance("t3lib_TCEforms_FE");
$this->tceforms->initDefaultBEMode(); // is needed ??
$this->tceforms->backPath = $GLOBALS['BACK_PATH']; // is empty... may not be needed
//////////REPEAT FOR EACH INPUT FIELD/////////
// start create input fields, here just a single select for responsible
// conf used for tceforms similar to but not exactly like normal TCA
$conftest = array(
'itemFormElName' => $GLOBALS['TCA']['tx_ogcrmdb_tasks']['columns']['responsible']['label'],
'itemFormElValue' => 1,
'fieldConf' => array(
'config' => $GLOBALS['TCA']['tx_ogcrmdb_tasks']['columns']['responsible']['config']
)
);
// create input field
$this->content .= $this->tceforms->getSingleField_SW('','',array(),$conftest);
// wrap in form
$output = '<form action="" name="editform" method="post">';
$output .= $this->content;
$output .= '</form>';
// wrap and return output
return $output;
Still looking for a working example with custem template for input fields.

How can I render a cObj or any cObj from any page but from an eID-ajax function on a specific page?

In an eID script I want to render all the content elements of a specific page with the function cObjGetSingle but it gives me an empty string? My code:
tslib_eidtools::connectDB(); //Connect to database
$cObj = t3lib_div::makeInstance('tslib_cObj');
$conf['tables'] = 'tt_content';
$conf['source'] = "551";
$conf['dontCheckPid'] = 1;
return $cObj->cObjGetSingle('RECORDS', $conf);
EDIT: There is a problem in class.tslib_content.php in the function cObjGetSingle? The function doesn't get executed because there is a crazy recursion loop check? The code:
// Checking that the function is not called eternally. This is done by interrupting at a depth of 100
$GLOBALS['TSFE']->cObjectDepthCounter--;
if ($GLOBALS['TSFE']->cObjectDepthCounter > 0) {
$name = trim($name);
When I call cObjGetSingle $GLOBALS['TSFE']->cObjectDepthCounter is null and after the check it's -1 so the function kills the loop. But why?
Edit 2: This doesn't solve the problem either: http://lists.typo3.org/pipermail/typo3-dev/2007-August/024497.html? Here is my conf-Array:
$conf = array (
'tables' => 'tt_content',
'source' => "551",
'dontCheckPid' => 1,
"conf." => array (
"tt_content" => "TEXT",
"tt_content." => array (
"field" => 'uid'
),
)
);
Edit 3: According to the post I'm not sure if it is a USER_INT / COA_INT or caching problem because the page I use this is uncached and I want to use an eID (ajax) function to render my content object??? I'm not sure how I can debug this?
Edit 4: Maybe the solutions is to create a cObj? http://www.mneuhaus.com/2008/12/05/function-to-make-a-cobj-in-typo3/????
Edit 5: Here is another shorter version: http://sebastiaandejonge.com/blog/articles/2010/september/21/bringing-ajax-to-your-frontend-plugins/?
You are missing a rendering definition below conf!
Have a look into tt_content at TSOB. On a normal page, this is there. Now you have to do it manually.

Add Database Row Button Cakephp

The Controller:
function add(){
if (!empty($this->data)) {
$qnote = $this->Qnote->save($this->data);
if (!empty($qnote)) {
$this->data['Step']['qnote_id'] = $this->Qnote->id;
$this->Qnote->Step->save($this->data);
}
$this->Session->setFlash('Your note has been saved.');
$this->redirect(array('action' => 'index'));
}
}
The Form.
<?php
$userID = Authsome::get('id');
echo $form->create('Qnote', array('action'=>'add'));
echo $form->input('Qnote.id', array('type' => 'hidden'));
echo $form->input('Qnote.user_id', array('value' => $userID, 'type' => 'hidden'));
echo $form->input('Qnote.subject');
echo $form->input('Qnote.body', array('rows' => '3'));
echo $form->input('Step.id', array('type' => 'hidden'));
echo $form->input('Step.user_id', array('value' => $userID, 'type' => 'hidden'));
echo $form->input('Step.body', array('rows' => '3'));
echo $form->end('Save Notes');
?>
This Form Adds Data in 2 Models.
Model 1 = Qnote;
Model 2 = Step;
I am able to add Data to the Models.
I was wondering I could add a button to the form
The Button would allow users to add multiple Step.data to the Step model.
Some like a +1 Button.
Basically I want to add multiple steps Per Qnote.
Could someone point me in the right direction how i can achieve this.
This is something I would do with jQuery. Basically all you need to do is using jQuery to dynamically add more inputs in the CakePHPs conventions: Step.0.user_id for example.
What you need to do now on a +1: you need to count the zero up, so you will get Step.1.user_id and so on.
First option: Use a jQuery-Script for doing this
var count = 1;
$('#add_step').click(function() {
var new_form = $('.Step').eq(0).clone();
$('input, textarea, select, radio', new_form).filter('[name^="data"]').each(function() {
var name = $(this).attr('name');
var new_name = name.replace(/\[\d*\]/, '['+count+']');
$(this).attr('name', new_name).attr('value', '');
});
$('#YourForm').after(new_form);
count+;
return false;
});
In this case you're cloning a div with the class step which holds your inputs for the model Step. You then replace the name-attribute to replace the zeros through the new value of the variable count. count++ enables you to add as many steps as you want.
This is an jQuery only solution and may require additional work for your environment.
Second option: Use AJAX with an element
You could also write a function in your StepsController which renders an element which holds your form and takes care of the counter.
Third option: Use a URL-parameter to decide how many options you want
If you have an URL like /qnote/add/3 you could use the 3 as a parameter in a for-loop to iterate through these form-inputs.
You need to take care, that eventually already typed in values are sent with the form when adding another Step so that these don't get lost.
Hope this helps to get on the right way.