Form with only a button - php

I have a html project with PHP and I want to be able to have a button that when I click on him, a POST request to be executed. The problem is that I want to be able to also send some parameters through the request but I don't want to have input fields.

I am afraid to say that it is impossible when you only use HTML each element of HTML have their usage and you can not send parameters like what you described the only thing you can send by a button is its name and value solutions to this situation is using hidden input type or sending these parameters by AJAX or socket as JSON for example. any sub-element of form tag in HTML will be received to the server as post global array and they generate by input fields inside the form so you can not have another input in the server if you don't create it in HTML unless you don't use HTML for requesting to the server I mean it's possible but not with HTML

Related

Getting selected text

I need to get a text that the user has select with pointer and put it to some variable in PHP. So, the user should select some text in one div, then click submit button (in another div), and then I need to store that part of the text to some variable. Can anybody help me?
You would have to set an onclick listener (I prefer to use JQuery for this) so that when the user clicks the submit button, you grab the selected text from the div. You could probably do that in a way found here:
Get the Highlighted/Selected text
Since javascript and HTML are front-end and PHP is back-end, you cannot simply place the selected value into a PHP variable. Instead, you can use an ajax request to send the data to a PHP function. I'm not sure what you are doing with it after that, but sending an ajax request and including the selected text in the data section of the request, and then retrieving it in your PHP file/function and storing it in a variable there. This question should help in that regard: Passing Javascript variable to PHP using Ajax

format and resend form data from PHP script as if it came from an HTML form

Is there a way that I can have a form that submits (via POST) a form element to a PHP script on my server... then have the PHP script re-encode the data and send to another server, as if it came from an HTML form?
I basically need to intercept one of my forms that users will use, so that I can record data (which are lists, nothing confidential or personal information) that the user selects in the first form, then it will be processed by my PHP script, but then I want it to be re-encoded as if it was coming directly from the original HTML form (as I have to submit some hidden fields to the final destination server after my PHP script works with the POSTed form data.
How can this be done? and if someone could give a simple example, I'd appreciate it. Thanks

cUrl on instagram to lookup accounts by email

Is it possible to search for an user (Not by their api https://api.instagram.com) but using php cUrl through the search box in their website at https://www.instagram.com/ (you have to login to see the search box at the top of the page)
I mean I know how to make a php script and make it log in and keep the session (learned from tutorials) but the problem is there are no action="" attribute in the form tag, nor there are any name="" attribute in their input tags.
I want to know what they are using as their backend?
I want to know how Instagram pass variables if their are no action and name attribute
How can I post using cUrl without the variable names.
The form input doesn't necessarily need a name attribute and also doesn't need to be in a form element with an action tag. Javascript could be used to get the input data and sent to the server using ajax or maybe change the address to search for what has been inputed.
Basically javascript could be used to get the data. In this case you won't be able to use cURL if you don't know the url that receives the input on the server.

Save entire form to file in php

I have a standard web page enclosed within a PHP form. Is there a way to save the entire contents of the form (HTML included) out as a it's own HTML file with the form answers included? The answers are either a drop-down selector or a standard text entry box.
I'd rather not have to generate a new HTML file with the responses if I can.
You can try to use javascript to capture the current html and responses of the form on submit, assign this code to a hidden form field and then submit the form. Having said that, I don't think this is a very reliable solution and also it really should'nt be so difficult to generate the same form with responses in php.

Sending POST data via href

Is there any way of sending post data via an anchor tag??
for GET data you just have to write it directly in the URL
but can we still do it for POST?
i need the link to be without any parameters and pass name=john via POST. can this be done?
Not with plain HTML.
You could use JavaScript to cancel the default behaviour of the link and submit a form (creating the form if needed).
jQuery('a').on('click', function (evt) {
jQuery('form').submit();
evt.preventDefault();
});
… but you shouldn't do that because links and submit buttons have different affordances and you'd be sending misleading messages to the user while adding an unnecessary dependancy on JavaScript.
If you want to make a POST request, then do it for the right reasons and do it with a form and a submit button.

Categories