I have output from a page (Uploader.php). Now i go to some other page and have a button on that page to reroute to this page (Uploader.php). I want the input of the page to be seen rather than reprocessing the page.
From what I can infer of the question you want to have a form that allows the user to upload whatever information. After they submit, you want to either show a 'review' page (for the user to confirm or deny the action to be performed), or a 'results' page to review what was performed/uploaded/input.
For easy of programming I would have two PHP files, Uploader.php and Uploader-View.php
Uploader.php would have your form and post to whatever form action script you have for processing it. The action script could then redirect to Uploader-View.php with the form values placed in the page as text, rather than as form fields.
If you wanted to re-use Uploader.php you could have some variable to determine the state of the workflow and decide whether to show form fields or variable values.
Related
I have a HubSpot form embedded into a WordPress page.
What I'm trying to achieve is gated and ungated content. See these use cases as an explanation:
User enters WordPress page for the first time on content that is gated by default (by gated
I mean it shows a form).
User fills out the form and gets redirected to whatever is specified as the redirect
option in HubSpot (the content is now ungated).
User closes the window but decided to back onto the WordPress page. Now, since the
user has already filled out the form (the cookie for hubspotutk
exists), I want the user to be redirected straight to the asset
(whatever is specified in the redirect option in HubSpot forms).
How far have I got?
I've created an ACF field in WordPress with radio buttons for Gated or ungated content. By default, all content is ungated.
I've then set a cookie based on this ACF field value. I.e. if the content is gated, resourceType cookie equals "Gated".
That's how far I have got.
The next steps (I think) would be to...
Only "ungate" the page if the user has filled out that form. For example, I've completed a form, the hubspotutk cookie value is "23a43a4a6de9c38f7657ebd08d574scf". How does HubSpot know which form this value is assigned to?
Other concerns:
If the user has filled out the form already, how to I redirect them straight to the asset? Is there a way to get the "redirect to another page" value in the image below as a variable?
I don't want to use HubSpot Forms API because I don't expect the admin to create the forms via the API. They'll want to create it via the HubSpot forms option.
Any ideas?
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('');
I have a form our guests use to submit a post to a very simple 'message board'.
Now we want to allow the users to upload 1-10 files, but the concern or requirement is to do this outside of the MAIN form submit.
MAIN FORM consists of:
input field 1
input field 2
text area 1
Submit button
I currently have it so there is an initial browse button.. ( below the text are and to the left of the main submit button) and once a file is picked.. and display a link for the user to add another 'browse' field..
What I would like to do is have an UPLOAD button below all these dynamically created browse/file upload fields... that will send all the file data to an external .php script to upload the files in question, and then just return the file path/name back to the main form (maybe in hidden fields? I dont care).. so that these file path/name string values are submitted when the MAIN FORM is submitted..
hope that make sense.
Is this possible? And if so how do I go about this? The concern is to handle the asset uploading/file handling outside of the main form submission so the users details are not lost if something goes wrong with the file upload portion of things.
You can do this with JQuery and Ajax. There are various plugins are available for this. You can try this - http://plugins.jquery.com/uploadfile/
My client wants to have a 3 page form. The first page allows the user to enter data including a uploaded file. the second page confirms this data. and the third page submits the data to the database and directories.
Via post, I can keep saving the data to a hidden input fields, thats no problem. My problem is the uploaded file. how do I hold that document from page to page ? I am using Cakephp but any advice would help, thanks
You can always just create the illustion that the form is utilising three different pages. Use AJAX to accept and validate/request the user confirm their submitted data. If in this view they accept it initiate a POST to submit all that data.
You really don't need three physically different files to achieve this but you can still let it appear in three stages to keep your client happy.
You just upload the file to temp directory and keep the value in hidden variables just like other form data . If form successfully submitted then the image copy to desired location other wise delete the image
You can easily fake these 3 pages using CSS. Or even 2, as "third page" is actually a server script which has nothing to do with pages in the browser.
Just make your form, then put an event on the submit button which changes divs to whatever "confirmation page" he wants. and then actually send the form using a button on this page.
that's all
An uploaded file is always held temporarily. The server env var should tell you where it is. In Ruby's rack it is stored in the params var. So I guess there is a similar params var in php which has a hash with all the necessary information.
Since the file would be uploaded on the first step, one option is to put the file's location in a hidden input field along with the rest of the data (either there, or put it in the session). With CakePHP, if your file field looks somewhat like that:
<input type="file" name="data[User][image]" id="UserImage" />
Then you will be able to capture the location through
$location = $this->data['User']['image']['tmp_name'];
Which will correspond to something like /var/tmp/xxxxxx
On the last page, if the user confirms all the data, you just use move_uploaded_file() to put the file wherever you want on the server.
move_uploaded_file($location, '/new/location');
Lets say I have a Page with a List (list.php).
I click on a row on that list to Edit that record. I go to a edit.php Page.
I have 3 buttons on that edit.php page. Save, Apply, Cancel
Save button - Saves the Record and returns to the (list.php) Page
Apply button - Saves Record but stays on the same page (edit.php)
Cancel button - No save, just return to the (list.php) Page
But now image if I can access for edit that item on a different page. How do I return to that calling page?
Do I add a parameter(code) to the URL? something like a Page Origination Code?
Do I save the previous page URL in a session? (bad, they can right click open another page and that would be saved to session url)
Am just curious to how others return to a previous page after a SAVE.
you can the server variable $_SERVER['HTTP_referrer'].
They are other ways also you can store in session the current page and use is processing page.
Adding a parameter to the URL is the only reliable though quote ugly way.
That's why such an in-place editions nowadays often being implemented using AJAX, and this very site is a perfect example.
However, there are different cases.
Login page is imperfect example for example, as you always have a form instead of just a link, and thus you can always store the current page in a hidden form field.
Another approach is possible if you are using some sort of front controller, and all requests actually being directed to the single index.php file which runs appropriate script based on the URI.
in this latter case you will need no more than mere a redirect to the current page.