Contact form in ruby, sinatra, and haml

前端 未结 5 959
天命终不由人
天命终不由人 2021-01-30 09:15

I\'m new to all three, and I\'m trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with

5条回答
  •  孤街浪徒
    2021-01-30 09:56

    I figured it out for any of you wondering:

    haml:

    %form{ :action => "", :method => "post"}
      %fieldset
        %ol
          %li
            %label{:for => "name"} Name:
            %input{:type => "text", :name => "name", :class => "text"}
          %li
            %label{:for => "mail"} email:
            %input{:type => "text", :name => "mail", :class => "text"}
          %li
            %label{:for => "body"} Message:
            %textarea{:name => "body"}
        %input{:type => "submit", :value => "Send", :class => "button"}
    

    And the app.rb:

    post '/contact' do
            name = params[:name]
            mail = params[:mail]
            body = params[:body]
    
            Pony.mail(:to => '*emailaddress*', :from => "#{mail}", :subject => "art inquiry from #{name}", :body => "#{body}")
    
            haml :contact
        end
    

提交回复
热议问题