PHP & Smarty - Submit form to self within Ajax Tab - php

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

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?

prevent dupplicate submitted by ajax

I'm using ajax to create list of replies.
In the end of the list I added textarea form that allow user to add reply (also with ajax).
The problem is that i call to my JS in my main PHP page so when user want to submit reply the page doesn't "know" the js code. If i add the js to the ajax php file/page the code will work but then it will be duplicated many times and when user will submit form the text will be submitted many times...
In my console i see that the JS file duplicate every time i load the replies list
How can i prevent it?
Disable the submit button right after user presses it once. Using jQuery:
$("#button").attr('disabled','disabled');
Make sure to remove disabled attribute on AJAX error so user can re-submit the form with new data. You can remove disabled attribute like this:
$('#button').removeAttr('disabled');
[improved]
if you want to not repeat data when navigation or F5 press, simply free the $_POST vars after doing whatever you want, and check if isnt set (before clean, of course) redirect you wherever you want. example:
/* HERE do the job with ajax response. */
if(!isset($_post['foo'])) header('Location: wherever.php');
$_POST['foo']=NULL;
If you're using $_GET... don't do it, use $_POST... $_POST is your friend.
Finaly ensure that if you press F5, you don't re-send form vars by post (otherwise you will get the same). If it's happening, clear your inputs with jQuery on page load.
$('#inputID').val('');

Codeigniter submit form written in plain HTML

I'm playing for about 2 days now and can't make this out. I'm working in codeigniter 2.1.0. and I want to submit a form that is written in HTML. I don't want to use the CI form helper.
The reason is because I'm dynamically with JavaScript adding things in the form. When a user clicks an item then it's added to the form. Now when the user clicks the submit button all the items I added should be sent in a POST request, but my POST is totally empty.
Now I noticed that the POST only gets sent when I use form_input() from the CI form_helper.
Is it possible to just submit a normal plain HTML form without using the form helper?
Is it possible to just submit a normal plain HTML form without using the form helper?
Yes. The actual submit is totally independent to CI, just ensure you use the correct action URI of the form so that the correct controller action is called by the form submit post (I assume your form method is post) request.
You do not need to use the CI form_helper for the submit button. If you mock a form with these you will see that those just generate plain HTML and do nothing magically.

Redirect form dependent url to open in an Iframe on an html or within the php file

Ok thanks to the great people on this site I was able to create a php file that directed to a form dependent variable url. What I would like to try and set up is to either mask the directed url so the variable url is not shown or at least have it open to an iframe so the address bar is at least not present.
Some things I have tried:
On the Form page created that has the action thats directed to a my php file I created an iFrame and set the target to the iFrames name------- iFrame shows up on the form, but upon submission full page loads, not in iFrame
Created an iFrame.html doc had the Form page action set to the html doc, then set the iFrame source in the doc to the php file with the action------same thing loads in the same window and no iFrame ever shows
Tried to insert iFrame in the php doc but got parsing errors
Any help would be appreciated even if its just a point in the right direction.
If you want to simply hide the parameters in he URL (for example to not allow users to easily edit them) you can simply change the form to use POST as opposed to GET: <form action="serverside.php" method="post">. On the server side you will also have to change $_GET to $_POST or $_REQUEST (the last one combines the get and post variables with post having higher preference).

PHP & AJAX - Submit form doesn't work because of AJAX

I'm making this contact form. The site itself uses AJAX to load the content in the main window. The problem with my form is that when the user clicks on submit and the data passes validation, it loads the page to main instead to itself to reach the actual mailing script.
Is there any way to pass this??
take the action our of the form opening tag
If you're using the Prototype.js library, you could just call event.stop() on a passed event object, on form submit.

Categories