Save entire form to file in php - 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.

Related

dealing with forms in php

I have only one php file called index.php. I have created there a form with one input text element and one input submit element. When I click on submit I want to deal with the value from the input element in the function that is in the same file, namely index.php. So my question is what to write into action attribute of the form element, if i will write index.php it doesnt work properly because then I get to the dashboard of wordpress. (I am trying to create a wp plugin).
-I am PHP and also Wordpress beginner-
I think the quickest way is just not to set any action on the form html tag. That way it will just POST/GET data to the same page from where you're calling it. Does this make it for you?

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

How do I echo the text of one input element to another input element in the same form using PHP and HTML?

I have two input elements:
one for typing
another for display the submitted text as a tag
These two input elements are on the same form.
I would like for a user to enter text into the first input element and then when they press "enter" on the keyboard the text is displayed in the second input field as a tag.
In the second input element I tried to execute this code but it is not working:
" />
Note: I am using Bootstrap 3 library.
Any help would be much appreciated.
use JS or jQuery for it.(something like this $('#yourelement').on('keyup',function(event){.....})); issues like this should be solved on client side, not on serverside using PHP.
to solve this issue with html+PHP only, you have to reload the page all the time after Enter press (you have to make a form and on Enter form will be submitted, then get this data in PHP and put in form again, BUT this is really bad way programming)
It won't work with PHP. PHP does not run in the browser only on the server side when the page is loaded. You need to use a client side language.

Linking an HTML form to a PHP file or just save it as a PHP file?

When creating a simple form which a PHP script will process, does it matter if we link to that form via the form tag? For example, we have:
<form name="studentapp" method="post">
With the PHP script being below the HTML form. The file is saved as a PHP itself, so it can interpret the PHP code. There isn't really anything special about the name. But how about this:
<form action="application.php" method="post">
Where the file is an HTML file, but it links to a PHP file for processing the data.
Is one better to use than the other?
EDIT: There is an error in the code I posted. One should use the action tag to link a separate PHP file for processing. (Thanks user Stony)
Both of them is wrong ;)
The action tag is to define the page to send the form to. The name is only an optional name to process the form via javascript for example.
<form name="myformname" action="application.php" method="post">
Besides of what's been said (that you need to use the action attribute) it depends on your workflow. If you want to display the form again, them it makes sense to keep everything on the same page. Or you can move your php processing block to the top of the page and exit if form has been submitted, therefore not showing the form again. I really don't think it matters if you use the same page or a different one. Again, it depends on your workflow.

HTML form within another form

I am new to html, I would be really glad if you can help me with this.
I have a web page where there is a list and some other text inputs and buttons. This option list can be populated by clicking the "add" button in the page, this add button is to direct to another page and in that page there are some chekboxes, those which are checked are loaded back to the main page,(where I have the list) .
At the end data in the main page needs to be loaded to the database, (what is in the list and in the text inputs).
Since I'm new I just know little about php and html, I thought I should have a form within a another form(form to "add items", form to load to the database) and it is not possible in html. Can anyone suggest the best way to do this? Do I need to use javascript?
Why can't the extra inputs (the ones that would be in the second form) be part of the first form? I think the question will become clearer if you post a sample form so we can see the relationship between the two forms.
But overall, since you're ultimately only submitting one form, then maybe all the inputs belong together. If what you're calling the second form isn't supposed to be visible right away, you can still have it be part of the same form, but only reveal it when needed.
Again, some sample data would help to understand the exact context of your question.
in php if you use input name="somename[]"
for a number of input elems
you will get an array in $_POST['somename'] and access all the values.
I think what you're after - if I understand you correctly - is ajax. Ajax allows you to asynchronously send data to/from another script without leaving the current page. This is accomplished using JavaScript. In your case I think what you need to do is set an onclick event in JavaScript to a button:
<input type="button" onclick="javascriptFunction()">
You can read more about ajax here:
http://www.tizag.com/ajaxTutorial/ajaxform.php

Categories