How do I add a hidden input tag using the Jericho HTML Parser? - jericho-html-parser

For each form in an HTML page I want to add an additional hidden input tag as it passes through a JEE Filter. For a given HTML page for example:
<html>
<form name="input" action="submit.jsp" method="post">
<input type="hidden" name="id" value="1"/>
<input type="submit" value="Submit"/>
</form>
</html>
the end result should be similar to this:
<html>
<form name="input" action="submit.jsp" method="post">
<input type="hidden" name="id" value="1"/>
<input type="submit" value="Submit"/>
<input type="hidden" name="dynamickey" value="DYNAMIC_VALUE_HERE"/>
</form>
</html>
As the HTML may be malformed, I am figuring that Jericho would be the HTML parser of choice. After a couple of passes through the web pages, I have found ways to change the values of already existing tags, but how to add an additional tag escapes me.
Thanks in advance for help.

Related

Jinput not working for joomla

I've been stuck on this problem with no clue as to why this doesn't work.
I'm using Joomla 2.5 and building my own component.
I have a 'Books' and 'Book' view. 'Books' lists all the books from the database and 'Book' is where I add/edit my book item. I'm trying to pass a value from 'Books' to 'Book' but it doesn't work.
I've set up an input text with a value to pass on.
<input type="text" id="test" name="test" value="testvalue" />
views/books/tmpl/default.php
<form action="<?php echo JRoute::_('index.php?option=com_test'); ?>" method="post" name="adminForm">
<table class="adminlist">
<thead><?php echo $this->loadTemplate('head');?></thead>
<tfoot><?php echo $this->loadTemplate('foot');?></tfoot>
<tbody><?php echo $this->loadTemplate('body');?></tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
<!-- For sorting -->
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<input type="text" id="test" name="test" value="testvalue" />
</div>
</form>
And in my book view.html.php file views/book/view.html.php
$jinput = JFactory::getApplication()->input;
echo 'value:'.$jinput->get('test');
There will be no value. I've tried $_POST('test') but it still doesn't work. Can anyone please point me at the right direction?
The Post data should be received in Controller not in view.
Once you submit the form it should have controller and model to handle the POST data.
check this link and understand the work flow, then on your controller you can try the same code it will works.
Joomla MVC component structure
Hope its helps..

Rails access uploaded file

I'm building a site on rails and backbone. On the front end I have a simple form:
<form action="/api/users" method="post">
<input type="file" name="profile_image" />
<input type="submit" value="submit" />
<input type="hidden" name="id" value="1">
<input type="hidden" name="method" value="put">
<input type="hidden" name="authenticity_token" value="<%= csrf_token %>">
</form>
When I post this form and print params[:profile_image] from my UsersController the line
logger.debug params[:profile_image].class
just returns
String.
Where's the file?
For what it's worth, I'm using carrierwave, but don't want to mount an uploader. I would just like to pass a file to myUploader.store!.
You need to set enctype on your form in order to submit files. See http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
Example
<form action="/api/users" enctype="multipart/form-data" method="post">

URL POST parameters

I want to make a program in C# which will go/login and do stuff on a website. I'm using Fiddler to see which URL should I use.
So, in Fiddler I write:
https://landfill.bugzilla.org/bugzilla-tip/post_bug.cgi?Bugzilla_login=mymail#hotmail.com&Bugzilla_password=mypassword&product=WorldControl&version=1.0&component=WeatherControl&rep_platform=All&op_sys=All&priority=P2&bug_severity=normal&target_milestone=World 202.0&bug_status=CONFIRMED&assigned_to=mymail#hotmail.com&short_desc=bla
And I send it with POST. I get a message which says: "Are you sure you want to commit these changes anyway? This may result in unexpected and undesired results."
Then, there is a button which says 'Confirm changes'. Its code in the result html page is:
<form name="check" id="check" method="post" action="post_bug.cgi">
<input type="hidden" name="product"
value="WorldControl">
<input type="hidden" name="version"
value="1.0">
<input type="hidden" name="component"
value="WeatherControl">
<input type="hidden" name="rep_platform"
value="All">
<input type="hidden" name="op_sys"
value="All">
<input type="hidden" name="priority"
value="P2">
<input type="hidden" name="bug_severity"
value="normal">
<input type="hidden" name="target_milestone"
value="World 2.0">
<input type="hidden" name="bug_status"
value="CONFIRMED">
<input type="hidden" name="assigned_to"
value="mymail#hotmail.com">
<input type="hidden" name="short_desc"
value="bla">
<input type="hidden" name="token"
value="aGipS2Hfim">
<input type="submit" id="confirm" value="Confirm Changes">
What should I write as URL in Fiddler or in browser to click this Confirm button?
You should submit POST data to URL https://landfill.bugzilla.org/bugzilla-tip/post_bug.cgi .
POST data should be as follows :
version=1.2&Component=WeatherControl& .... etc
Don't forget to encode POST data and set content type to "application/x-www-form-urlencoded"
UPDATE: When you receive first answer with confirm button, parse it as DOM and submit it again to same URL.This should behave same as you click on confirm button
The problem was that the parameters shouldn't be in the URL. This isn't GET method.

MVC Razor String Concat

I am using Razor to generate a form. I want to create HTML elements based on some value from it's model property.
for example, if a model contains Id property, and I want to generate html tags as follows
<input type="hidden" name="1_chk" />
<input type="hidden" name="2_chk" />
<input type="hidden" name="3_chk" />
So I used the following syntax, and it failed. Can anyone help me out with this?
<input type="checkbox" name="#Id_chk" />
Thanks
I think this should work for you:
<input type="checkbox" name="#(Id)_chk" />
another option:
<input type="checkbox" name="#(Id + "_chk")" />

Get posted values from dynamically added controls in ASP.NET MVC

I have a form in which i'm dynamically addding controls through jQuery. I need to access the values in those controls (textboxes) when posting back the form to the server. I'm sure this is a trivial problem but i just can't get my head around it.
Any help would be greatly apreciated.
When adding a multiple controls to the page, give them all the same name attribute so you can do the following in your action:
public ActionResult MyAction(string[] items)
{
// items will contain all the values in the text boxes
return View();
}
So your HTML would like like this
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />

Resources