Html form submit action url

HTML, making a button submit data to another url?

I have the form and it POSTs to login.php but I want the button Make a new account post the same data to register.php. Is that possible? If so, how?

5 Answers 5

Set action attribute of your form tag to the URL of the page to send the data to.

i thought, and actually do, the same for all languages i’ve worked with, except for MS Razor pages, where it seems it doesn’t work, since it posts to the same url from the browser

In .NET Core 3.1 at least, I’m able to set the asp-page and asp-route-. attributes on the input tag used for submission. You need to create a shell cshtml file so that url generation works. The end result is a formaction attribute that routes the form to the correct Razor page POST handler.

In HTML add an onclick event handler for Make a new account button:

 

If this does not work, you may try:

One or both of the above mentioned solution should work for you. Prefer the first approach as it is cleaner.

Please take this as a starting point not a copy-paste solution and follow the best practices for development.

@ItayGal, there are two submit buttons on the form. The asker wants to submit the same form to two different URLs depending on the button clicked by the user. So, we are using the default value for action attribute for one button and updating action attribute on click of the second button.

I have the form and it POSTs to login.php but I want the button Make a new account post the same data to register.php.

Is that possible?

In HTML5 it is, using the formaction attribute on the submit button.

But browser support is probably not so good yet. Could be resolved using a Polyfil that attaches click handlers to such buttons automatically and changes the action attribute of the form dynamically, though.

Источник

HTML action Attribute

On submit, send the form-data to a file named «action_page.php» (to process the input):

Definition and Usage

The action attribute specifies where to send the form-data when a form is submitted.

Browser Support

Syntax

Attribute Values

  • An absolute URL — points to another web site (like action=»http://www.example.com/example.htm»)
  • A relative URL — points to a file within a web site (like action=»example.htm»)

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

Атрибут action

Указывает обработчик, к которому обращаются данные формы при их отправке на сервер. В качестве обработчика может выступать CGI-программа или HTML-документ, который включает в себя серверные сценарии (например, Parser). После выполнения обработчиком действий по работе с данными формы он возвращает новый HTML-документ.

Если атрибут action отсутствует, текущая страница перезагружается, возвращая все элементы формы к их значениям по умолчанию.

Синтаксис

Значения

В качестве значения принимается полный или относительный путь к серверному файлу (URL).

Обязательный атрибут

В HTML4 и XHTML обязателен, в HTML5 не обязателен.

Значение по умолчанию

В качестве обработчика можно указать адрес электронной почты, начиная его с ключевого слова mailto: . При отправке формы будет запущена почтовая программа установленная по умолчанию. В целях безопасности в браузере установлено, что отправить незаметно информацию, введенную в форме, по почте невозможно. Для корректной интерпретации данных используйте атрибут enctype=»text/plain» в теге .

Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.

Типы тегов

HTML5

Блочные элементы

Строчные элементы

Универсальные элементы

Нестандартные теги

Осуждаемые теги

Видео

Документ

Звук

Изображения

Объекты

Скрипты

Списки

Ссылки

Таблицы

Текст

Форматирование

Формы

Фреймы

Источник

How to add a form action button to your HTML form

A form action button is a button element that is used to submit a form to a server. It triggers the form submission when clicked, and sends the form data to the server for processing.

It’s the “submit” button

However, the button that submits the form is often called a “submit” button and is created using a tag with type=»submit»

button type="submit">Submitbutton> 

The button can be styled using CSS. For example, if you are using Bootstrap framework,

button class="btn btn-primary" type="submit">Submitbutton> 

The action attribute of the form

The action attribute of an HTML form element specifies the URL to which the form data will be sent when the form is submitted. This URL is typically a server-side script that processes the form data and generates a response.

When a user submits a form, the browser sends an HTTP POST request to the URL specified in the action attribute, along with the data from the form fields. The server-side script can then process the form data and generate a response, which is sent back to the browser and displayed to the user.

Here is some code that shows the action attribute and a button that submits the form:

form method="POST" action="/submit-form">  label for="name">Name:label>  input type="text" id="name" name="name">   label for="email">Email:label>  input type="email" id="email" name="email">   label for="message">Message:label>  textarea id="message" name="message">textarea>   button type="submit">Submitbutton>  form> 

In this code example, we have a simple form that asks for the user’s name, email, and message. The form element has two attributes: method and action. The method attribute specifies the HTTP method to use when submitting the form, which is POST in this case. The action attribute specifies the URL that the form data will be submitted to, which is /submit-form in this case.

How to create the server-side script that receives the form submissions

Even though you have completed your form with a button to submit the form, you still need a server-side script that will receive the form submission and perhaps sends you an email and saves the form data to a database for record keeping.

You can find such a script here. The script is written in PHP. So you should be comfortable editing PHP script to be able to use the script.

That’s a catch! You need a server and a script running on the server to handle form submissions. However, there is an easier solution. Use Ratufa form back-end.

Pro Tip: Attach a form handler with just one line of code

Ratufa is a form back-end as service. You just have to add one line of code to your form page and the form immediately becomes fully functional.

  • Go to Ratufa and press the connect my form button. It shows a line of code that has to be added to your form page.
  • Update your page with the code and test submit the form. You can now see the form submission data at Ratufa.io . You can even configure email notifications whenever the form is submitted.

See Also

Categories

  • Form Action
  • Contact Forms
  • Code Snippets
  • HTML Forms
  • Best Practices
  • HTML5 Forms
  • Form Widgets
  • PHP Form Handling
  • jQuery Form Handling
  • Email Forms
  • Form Mail
  • Web Forms
  • Calculation Forms
  • Checkboxes
  • File Upload
  • Google Forms

Источник

Читайте также:  Пример нейронной сети на питоне
Оцените статью