How can I access a form-Element, which has neither a name or an id? - forms

How can I access a form-element, which has neither a name or an id?
I didn't find any useful methods for the class HtmlForm.

You can use getElementsByTagName but you should know the structure of html.
For example :
HtmlPage page = webClient.getPage("http://www.tizag.com/phpT/examples/formex.php");
HtmlElement form = (HtmlElement) page.getElementsByTagName("form").get(0);
System.out.println(form.asText());
The code above lets you access the first form element and prints its content as text to console .

Related

SilverStripe custom form retrieve values for form fields

I have a problem with my front end admin update page. How can I retrieve values from a SiteTree page and populate it into a custom form? Is the setValue($values) function the only way? If yes, which is the best method to get the page variable?
I am using this:
$evens = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
I'm getting values from an ID of a draft page. After I get variables and values like that:
$field = new TextField('Titre', 'Titre');
$field->setValue($evens->Titre);
or
new TextField('Titre','Titre', $evens->Titre);
Which is the better solution?
The solution is 2 part:
Use TextField::create($constructor, $args) instead of new (optional, but not doing so is a pet hate of mine).
Set all fields at once: http://api.silverstripe.org/3.1/class-Form.html#_loadDataFrom

Get the properties of reference pages - Kentico

I have a page where I need to display testimonials, In that page document type I have a field to assign testimonials by using page selection, so It will save the GUID of selected testimonial in the database,
I have used following code to display the description of Testimonial, But is there any other way to get the document fileds by passing the GUID,
One option I can use is write a custom macro.
{% Documents["/Page-Resource/Testimonial/Testimonial"].getValue("Description") #%}
Note: I have used the text/xml type transformation
Well it's not that easy but there is one way and that is to use loops:
r = ""; foreach (i in CMSContext.Current.Documents) {if(i.NodeGUID == "a88f82be-bb76-4b82-8faf-5253209f0f75"){r = i}}; r.Description
Notes:
Use NodeGUID or DocumentGUID based on what you store in your custom field.
Replace the hardcoded guid with something like CMSContext.Current.CurrentDocument.YourDescriptionFieldWithGuid
See the documentation if you have any doubts about K# syntax

Drupal, overriding add/edit form forms for custom content type

I have created a new content type called protocol. The problem is that when you define a content type that means you also say how in the form the content is to be added and edited, like which form elements there will be.
A protocol is a content type that stores a title, an abstract and instructions. I want to add the title/instructions/abstract through one textarea where you tag the parts of the text like this:
[title]This is a title[/title] [abstract]This is an abstract. [/abstract][instructions]And these are my instructions.[/instructions]
That text is then processed and the content between each tag can be picked out and stored in a variable which should then be stored for the content type just like it had been added through a seperate field/textarea in a add/edit content form.
Is this possible to do? What kind of things should I read up on? Where in the drupal code are the function/functions that describes what happens when you push "Save" for a new content type for the standard add content form?(I just want to read it, not change anything)
Not sure this exactly matches what you're trying to do, but in a basic sense it should get you towards your goal. I wrote a module called endorse for Drupal 6 that provides a custom form feeding the submitted values into a new node:
http://drupal.org/project/endorse
Here's the form definition:
http://drupalcode.org/project/endorse.git/blob/refs/heads/master:/endorse.module#l136
Some basic validation follows and then the actual node save occurs at the top of the submit function, here up to line 231:
http://drupalcode.org/project/endorse.git/blob/refs/heads/master:/endorse.module#l206
The rest in that function is irrelevant except for the thank you and redirect at the very end of the submit function. If you're doing this in D7, it'll change a bit (see api.drupal.org for function definitions and whatnot), but it should look more or les the same.
Steps to solve your problem.
Create a module. Implement hook_menu with your custom add page.
Create a custom form using FORM API that it's gonna be displayed in your new page.
In your hook_form_submit get your values from the variable form state.
Parse the text and create and save a new node (snippet here).
$newNode = (object) NULL;
$newNode->type = 'protocol';
$newNode->title = $parsed_title;
$newNode->uid = 1;
$newNode->created = strtotime("now");
$newNode->changed = strtotime("now");
$newNode->status = 1;
$newNode->comment = 0;
$newNode->promote = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
// add CCK field data
$newNode->field_{YOUR_CUSTOM_FIELD_1}[0]['value'] = $parsed_data1;
$newNode->field_{YOUR_CUSTOM_FIELD_2}[0]['value'] = $parsed_data2;
// save node
node_save($newNode);
Those are the basic steps. If you have any more questions please ask.
TIP: Install the Devel module and use the function dpm() when you need to know the contents of some variable. You are probably gonna need it when you are implementing hook_form_validate or hook_form_submit for knowing the contents in the variable $form_state.
So just do:
dpm($form_state); //this will give you the variables inside the array with a krumo view.

C# .NET 4.0 Get the Value of an ID of a web element by reading the .aspx page with filestream or streamreader

So here's the problem I am writing a program that is going to look through the folder on the localhost before it is rendered. I want to be able to get the value of the ID of a web element and store that in a list object.
For example I have a page:
<html>
<body>
<CustomControl:MyPhoneValidationControl ID="PhoneValidator" validationgroup="PageValidation" />
<CustomControl:MyEmailValidationControl ID="EmailValidator" validationgroup="PageValidation" />
</body>
</html>
The program will go to C:\WebFolder\Page.aspx and then will read the file and find every CustomControl on the page and then grab the Control Type (MyPhoneValidationControl OR MyEmailValidationControl) and then assign the value of the ID (PhoneValidator, EmailValidator) as a property of the Control object.
I am using C#.NET 4.0. Getting the ID of the element is easy after the page is rendered but it doesn't show that it is a custom control. To see the custom control you need to look at the .aspx file without it being rendered by a web server (IIS, etc.)
I resolved myself this by stuffing the page data into a string and then using
string page = new StreamReader(page).ReadToEnd();
List<string> control = new List(string)();
MatchCollection matchControl = Regex.Matches(text, "expression");
foreach (Match match in matchControl)
{
control.Add(match.Value)
}
This catches the control to a list and then I can parse the string list to get the type and ID using Regex in the properties after passing the whole control List to the controls constructor.

GWT - Create a link to external website

I need to create a link that point to another website, not to the portal itself trought ajax call. I write this at the moment :
InlineLabel fv1=new InlineLabel("Validator W3C : ");
InlineHyperlink linkfv1 = new InlineHyperlink("HTML" , "http://validator.w3.org/");
InlineLabel fv2=new InlineLabel(" | ");
InlineHyperlink linkfv2 = new InlineHyperlink("CSS" , "http://jigsaw.w3.org/");
but it call the portal. In fact, if i click on HTML it adds #http://validator.w3.org/ in the navigation bar. How can I fix this? Bye
The docs for InlineLabel say that it's meant to be used for "internal" links -- i.e., only to change the part after the #, like you're seeing.
You want to use Anchor -- this will result in an <a> tag being added to your page.
I prefer this solution:
Define an object of HTML class with the necessary parameters then add that object to a container in your GWT interface, FlowPanel for instance.
HTML link = new HTML("Take me to stackoverflow");
flowPanel.add(link);