Symfony will not populate a form with large string after bind() - symfony1

I am having issues trying to override the value of a form field after submission. Currently the form includes a textarea and file upload input, but only one is used. If the user uploads a file it is parsed into text. I want to use the data that is parsed from the file as the value for the textare when the page reloads, rather than what was in the text box (empty). The content can not be determined until after the bind.
What I did was just bind the data again to manually set the value of the textarea after the document was parse. It works great if I hard code a value for the value, however when I use the full contents of the file, nothing is put in the textarea. There isn't some sort of length limit or something that could interfere with the population is there? I have tried short strings and they work fine, but these files are about 4k in length and won't populate in the text area.
Works
$this->form->bind(array('text'=>'1234'), $request->getFiles('profile_generate') );
Does not work, even though the value text is actually being set.
$this->form->bind(array('text'=>$largeString), $request->getFiles('profile_generate') );

FIX:
I suppose whatever function that Symfony uses to populate the fields from the bind() values has a problem with non-standard characters. Unfortunately it does not complain about it or let on to what the issue really is. After cleaning up the data, it worked fine.
$largeString = preg_replace('/[^(\x20-\x7F)\x0A]+/',' ', $largeString);
$this->form->bind(array('text'=>$largeString), $request->getFiles('profile_generate') );

Related

How do I copy the values of one form element to another?

This is a follow up to this questions:
How can I manipulate a form / inputs to be ignored when a form is submitted
I have the info displayed, the form, the show()s and hide()s, etc. Most everything seems to be progressing fairly well. Where I could use some input - no pun ontended - is on how to take the new values in the form and copy those to the display only div as part of the ajaxSuccess.
I can copy type=text and textarea but what about checkboxes, multi-selects and radios.
In short, once the new values in the form are submitted, I need to update the page (not as a form) with those new values. Perhaps I need to write some for each form element type? Even so, I'm not quite sure where to start.
Pardon me if my working isn't clear. If that's the case just ask what you'd like me to clarify.
The way that will make most sense is to have the script that is processing your form return the form contents in the ajaxSuccess data. Here's an example:
The javascript:
$.ajax({
url: 'ajax/process.php',
success: function(data) {
// Load returned data into page
$('#result').html(data);
}
});
The php:
var $input1 = $_POST['input1'];
var $input1 = $_POST['input1'];
// DO SOMETHING WITH VARS AND IF SUCCESSFUL RETURN
if($success){
echo "Thanks! Here is your info: ".$input1." and ".$input2;
}
Once the data has been returned you can manipulate it anyway you like. For example if you needed to separate out the different values from the form you could post a comma separated string back from the PHP and use the javascript .split() method to create an array from that string.
Hope that's helpful :)
I'd say that your best bet is to take a different approach altogether, and reload your content from the database after it's been updated - in this case via an AJAX call. The reason being that your posted content from the form may not match what ends up being saved to the database, as some of your fieldtypes may process and alter the data they're passed (for example, stripping tags, formatting text, etc). This way the refreshed content exactly matches what is displayed when the same content comes from the Channel Entries call.

Can someone explain Rails behavior for multiple fields with identical names and ids?

I needed to create a input mask for a jQuery datepicker in my Rails app, where the first form field uses m/d/yy format and the datepicker populates a hidden input with the proper database format.
I was using SimpleForm, and so I extended my own input so that the input is preceded by the mask.
I got everything set up and when checking out the browser, it all just worked well before I thought I would be done.
The form ends up with two inputs for the same attribute, each with the same id and name. I never thought this would work. Checking the development log I only see one date getting submitted, the second of the two which is the one that has the proper format for the database.
Is this all okay? Should I take some extra steps even though this appears to work fine, and more importantly, can someone explain what's going on under the hood that results in this behavior?
Thanks!!
Rails uses the Hash params to store fields submitted. When you declare two or more inputs using the same name, it happens the same as if you do something like
h=Hash.new
h[:name]="foo"
h[:name]="bar"
Result is bar because the foo was overwritten. So the "winner" is always the field value which the browser last appended to postdata.
But if I where you, I would not rely on the browser that the second field gets appended at last.

ListGridRecord in smartGWT not displaying items after '<'

I have a ListGrid with ListGridRecords where I am trying to display the straight xml output from a call I'm doing on the backend. Here's an example:
lgr.setAttribute("XML", "<xml><response>Bob</response></xml>");
However, when it goes to display the contents of lgr in the ListGrid, it doesn't display it. (i.e. it is blank). If I make the field editable, I can double click on the cell and it will then display it. Also, if I get rid of the '<' symbols it displays as well. However, that kind of defeats the purpose since I want to display the exact xml used.
Do I need to escape the '<' somehow in the ListGridRecord? What is the best way to do this in GWT?
Ok, just found a thread that seems to solve my problem at least halfway. I would still like to enable the user to copy it without the encoded values, but at least now they can see it. I believe I'll enable some sort of click handler on the fields to to enable the correct copying.
http://www.gwt-ext.com/forum/viewtopic.php?f=7&t=2693

how to return url in form file in strut

hai all,
i have one problem regarding to return the form file value is validation fail. i have one form that have a few field to be fullfil by the user and one attachment field.if one of the field is blank the system will give the error when submit the form..my problem is, all the field will have the value that we entered before this but for form file it disappear.
Let's see if I understand your issue: You have a form with several input fields, and among them a <input type=file> for uploading some file content. In case of validation error, you return to that page (with struts2 result = INPUT, I guess) and the content of the previously filled fields appears, except for the FILE field.
This makes sense, if you understand how the other fields are "refilled" in Struts2 in this scenario (just from the action, which has typically mapped the parameters to properties). The server doesnt know the (clientside) fullpath of the file, it is not sent along the http request (it would be a privacy issue), it's the content of the file what is uploaded (and perhaps the filename without path). You can't escape that.
Anyway, I think this a case in which validation should signal an error early (in javascript, in the client side). Think about it: the user is uploading a file (potentially large) together with other info, and AFTER uploading it the server checks the fields and instructs the user to refill the fields and retry (including the upload). This can be unacceptable. My advise is, then, to include client-side validation (and if it pass, and the server validation fails, then the user must resign to refill the FILE field). If the file is large, one could split the input form in two pages, a first one to fill the several fields, and afterwards another to upload the file.

Fill a rails form with a hashmap

I have a difficult situation.
I let the the user create a form through a Rich Text Editor and then I save this.
So for example, I save this literally into my DB:
http://pastebin.com/DNdeetJp (how can you post HTML here? It gets interpreted, so now I use pastebin...)
On another page I wrap this in a form_tag and it gets presented as it should be.
What I want to do is save this as a template and save the answers as a hashmap to my DB.
This works well, but the problem is I want to recreate what checkbox/radiobutton/... is selected when the user goes back to the page. So I want to fill the form with the answers from the hashmap.
Is there a way to use a 'dummy' model or something else to accomplish this?
Thanks!
Since you're pasting in raw HTML which is not properly configured as a template, it is more difficult to enable the proper options based on whatever might be stored in your DB.
The reliable approach to making this work is to use Hpricot or Nokogiri to manipulate the bit of HTML you have and substitute values accordingly. This isn't too hard so long as you can define the elements in that form using a proper selector. For example, create a div with a unique id and operate on all input elements within it, comparing the name attribute with your properties. There may even be a library for this somewhere.
The second approach is to use JavaScript to enable the options in much the same fashion. This seems like a bit of a hack since the form itself will not have a proper default state.

Resources