Obsługa formularzy

0

Witam po dość długiej nieobecności. Mam kilka pytań i bardzo proszę o pomoc w ich rozwiązaniu.
Mam taki fragment kodu w HTML'u. Moje pytanie brzmi :

  1. Jak za pomocą programy napisanego w Delphi dodać tekst do textarea.
  2. Jak wysłać taki formularz.
<form id="comment_form" method="post" action="www.stronka.pl/dodaj" >
    <textarea  id="comment" name="com_txt" rows="5" cols="40"></textarea>    
    <div class="buttons">
        <button type="submit" class="type_1">
        <table>
            <tr>
                <td class="button_add">Dodaj</td>
            </tr>
        </table>
        </button>
    </div>
</form>

Rozwiązanie było by proste gdyby wysyłanie odbywało się metodą GET, lecz w tej sytuacji nie wiem jak sie za to zabrać. Z góry dzięki za pomoc.

0

podstawowe pytanie.. szukales? z tego co ja pamietam to bylo juz wieele razy poruszane na forum. o czyms takim jak google juz nie wspomne.
http://www.google.pl/search?q=delphi+fill+web+form+post+submit

0

No wlasnie szukalem tylko nic nie dziala, mialem to tak

uses mshtml

function GetFormByNumber(document: IHTMLDocument2;
    formNumber: integer): IHTMLFormElement;
var
  forms: IHTMLElementCollection;
begin
  forms := document.Forms as IHTMLElementCollection;
  if formNumber < forms.Length then
    result := forms.Item(formNumber,'') as IHTMLFormElement
  else
    result := nil;
end;

procedure SetFieldValue(theForm: IHTMLFormElement;
    const fieldName: string; const newValue: string);
var
  field: IHTMLElement;
  inputField: IHTMLInputElement;
  selectField: IHTMLSelectElement;
  textField: IHTMLTextAreaElement;
begin
  field := theForm.Item(fieldName,'') as IHTMLElement;
  if Assigned(field) then
  begin
    if field.tagName = 'textarea' then
    begin
      textField := field as IHTMLTextAreaElement;
      textField.value := newValue;
    end;
  end;
end;

  document := WebBrowser1.Document as IHTMLDocument2;
  firstForm := GetFormByNumber(document,0);
  theForm := GetFormByNumber(WebBrowser1.Document as IHTMLDocument2,0);

  SetFieldValue(firstForm,'com_txt','asdfasd');

to nie dziala niewiem dlaczego
a jak daje takie cos

function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if form1.WebBrowser1.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Showmessage('nera formu');
    Exit;
  end;
  //count forms on document


  for I := 0 to Form1.WebBrowser1.OleObject.Document.forms.Length - 1 do
  begin
  form1.memo1.lines.add(WebBrowser.OleObject.Document.forms.Length - 1);
    FormItem := Form1.WebBrowser1.OleObject.Document.forms.Item(I);
    form1.memo1.lines.add(FormItem);
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Value := Value;
          Result := True;
        end;
      except
        ShowMessage('ajajai klaida');
        Exit;
      end;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  document: IHTMLDocument2;
  firstForm: IHTMLFormElement;
  theForm: IHTMLFormElement;
begin
  FillForm(Form1.WebBrowser1, 'com_txt', 'asdfasd')
end;

to wyswietla nera forum czyli ze nie znalejziono formulaza :/

1 użytkowników online, w tym zalogowanych: 0, gości: 1