dealing with forms in php - 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?

Related

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.

PHP & Smarty - Submit form to self within Ajax Tab

I have an ajax tab with a form inside it, with url http://example.com/tabs.php#pg=3, and I'm trying to submit the form to this tab using {$smarty.server.REQUEST_URI}, and although this does in fact submit the form to the correct .php file (used by the ajax tab), it is no longer contained within an ajax tab (I end up at http://example.com/formhandle.php).
Does anyone have an idea of how to submit the form to itself contained within the ajax tab? I've tried submitting to the URL of the specific tab (http://example.com/tabs.php#pg=3), however if I do this, the form post isn't actually handled. I'm stuck on this one.
Your code within formhandle.php would need to be moved to or included in tabs.php

open new TCPDF after form post

I have a form, test.html, (create in JS using dhtmlx, unimportant) that I want to submit to a PHP script, generateReport.php
generateReport.php creates a PDF using the information posted from the test.html using the TCPDF libraries.
How can I post the variables from test.html, and have the page redirect to the filled in PDF? I would prefer not to store it, but that really is not a problem if I store it temporarily.
Try to post the form to generateReport.php by using form action.
And Just get all you form values by using $_POST['form_field_name']
I think this will help you to get all form values.

How do you extract a HTML link text node in PHP once link is clicked?

I am using a PHP foreach loop to list a series of links on a HTML page, which are rendered using jquery mobile. When one of the links is chosen, I want to be able to use the link label in PHP code to query a database and generate the header and other data for the destination page.
The problem is detecting which link was chosen. It seems that an "onclick" event would be involved, but that might mean using Javascript. I've seen an example of placing PHP inside a HTML form, but that relies on using a submit button to create a $_POST input. In my case, the link would be the only button involved in the event,so creating a separate Submit button would not make sense.
You can add query parameters to the links. (e.g. ?id=foo) and then pick them up in PHP via $_GET['id'].

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