Jump to content

Having a button induce PHP


coolgamer48

Recommended Posts

You can have a submit button that sends the form data to PHP + a special value that when present will trigger that PHP function. PHP will then output the same form data it received, but it will also add that extra field because of the special value.You may also use JavaScript to do this on the client side. Ideally do both - JavaScript because it's faster for simple things like this and won't cause a page reload, and simple form submission for users with JS off.

Link to comment
Share on other sites

You can have a submit button that sends the form data to PHP + a special value that when present will trigger that PHP function. PHP will then output the same form data it received, but it will also add that extra field because of the special value.You may also use JavaScript to do this on the client side. Ideally do both - JavaScript because it's faster for simple things like this and won't cause a page reload, and simple form submission for users with JS off.
I realized the submit thing would work, but I wanted to have a separate button. Is the only way to do that with Javascript?
Link to comment
Share on other sites

I realized the submit thing would work, but I wanted to have a separate button. Is the only way to do that with Javascript?
PHP is only executed on the server, and thus - when there's a request to the server. A request is triggered only by the user following a link, submitting a form, or with JavaScript's XMLHttpRequest object.So yes. The only way to do something like that without form submission is with JavaScript. Whether you send XHR or use JavaScript itself for the insertion is up to you (though I'd suggest using JS itself rather than sending an XHR for that).
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...