0

This is probably very easy, but i just cant seem to find a good answer for myself.

I have this simple HTML Form in my ruby on rails.

  <form target="_blank" action="https://api.xxx.xxx/campaign_id=5011?randomtext">
    <label for="campaign_id">ID:</label>
    <input type="text" id="campaign_id" name="campaign_id"><br>
    <input type="submit" value="Submit">
  </form>

Looks like this https://i.stack.imgur.com/aEBN5.jpg

What i need:

So user can enter a number and when submit is cliked then the number in the (Form action) URL, in this example the "5011" is replaced with the number given by the user.

So the URL is "https://api.xxx.xxx/campaign_id=5011?randomtext"

when a new number is given and submited. lets use 6050.

Then when submit is clicked, URL changes to "https://api.xxx.xxx/campaign_id=6050?randomtext"

BrandoN
  • 193
  • 10
  • That is not even a valid url? The question-mark should be before the `campaign_id`. Should it not be `https://api.xxx.xxx/random_text?campaign_id=1234` ? If you use the url without the `campaign_id` the form will then post the campaign_id to your controller. – nathanvda May 27 '20 at 11:54
  • 1
    Finally found the problem i had in the post below. https://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear – BrandoN May 28 '20 at 09:35

1 Answers1

1

You can create action in your controller with code

Net::HTTP.get(URI.parse("https://api.xxx.xxx/campaign_id=#{params[:campaign_id]}?randomtext"))

(or using HTTP Gem, HTTParty or any other way)

And in your view something like

<%= form_with url: your_path do |form| %>
  <%= form.text_field :campaign_id %>
<% end %>
mechnicov
  • 12,025
  • 4
  • 33
  • 56