Just a brief question on the correct way to approach this. I am allowing form posts to a database without user registration, where each post will be reviewed. However, the page will be a multi-page form including file uploads.
What do I do if the user goes through the first few pages of submitting the form, including uploading files, and then abandons the form submission.
How do I go about cleaning up the unneeded data and uploaded files, whilst still making sure I don't remove it if they are in the process of posting it.
I was dealing with similar issue. My situation was a little bit different. I needed to give an option for the user to post an advertise and in the same time to allow him to upload images.
I approached this by putting a hidden field in the form that was holding the uploaded image filenames. For the upload itself I used ready library dropzone.js, as you already experience the problem with abandoned form process I simply decide to put the files in a temporary location /temp
and then if the form is actually completed then based on the value in the hidden field I am moving those images from the /temp to their permanent location. The leftovers in /temp folder can be easily then removed by a scheduled job that checks their creation time and deletes those that a day old for example.
Hope this gives you some ideas.
Another idea to make 1 huge form, but split it to several steps with JavaScript. Only button in last tabs submits form, while other buttons just show next step. You can do weak validation with after "next" action, and strong validation on server after form is submitted.
http://jsfiddle.net/ht227xy3/1/
<script>
function switcher(activeBlock, passiveBlocks){
document.getElementById(activeBlock).style.display='';
for (i in passiveBlocks){
if (document.getElementById(passiveBlocks[i]))
document.getElementById(passiveBlocks[i]).style.display='none';
}
return false;
}
</script>
<form onsubmit="alert('Now form submits!!!')" action="" method="post">
<div id="first" class="tab">
<h3>Step 1 of 4</h3>
<b>Field 1:</b> <input type="text" name="field1" value="" /><br />
<br />
<button type="button" onclick="switcher('second', ['first','third','fourth']);">Next</button>
</div>
<div style="display:none;" id="second" class="tab">
<h3>Step 2 of 4</h3>
<b>Alt 1:</b> <input type="text" name="alt1" value="" /><br />
<br />
<button type="button" onclick="switcher('third', ['first','second','fourth']);">Next</button>
</div>
<div style="display:none;" id="third" class="tab">
<h3>Step 3 of 4</h3>
<b>Extra 1:</b> <input type="text" name="extra1" value="" /><br />
<br />
<button type="button" onclick="switcher('fourth', ['first','second','third']);">Next</button>
</div>
<div style="display:none;" id="fourth" class="tab">
<h3>Step 4 of 4</h3>
<b>File 1:</b> <input type="file" name="file1" /><br />
<br />
<input type="submit" value="Submit" />
</div>
</form>
Related
I have a form which I've created and trying to make it upload image to the WordPress database. I'm not sure if I'm going the right way about it but created an SQL database and given myself all privaleges obviously. It's a dating section of the site so don't want it to be read by anything other than those using it (I'm assuming that My SQL is secure and functions privately without being readable by bots/spiders etc?
So I have the form like so (reduced version) and it's upload submit functions
<b>Add Photo</b><input
id="fileupload" name="fileupload"
type="file" value="fileupload" />
<label for="fileupload"></label>.
</div>
<div class="ur-field-item field.
checkbox">
<p id="check_box_1555917793_field"
class="form-row validate-required"
data-priority=""><label
class="checkbox required=" data-
label="Agree">
<input id="check_box_1555917793"
class="input-checkbox ur-frontend-
field "
name="check_box_1555917793"
required="required"
type="checkbox"
value="1" data-rules="" data-
id="check_box_1555917793" data-
label="Agree" data-value="" />
Agree <abbr class="required"
title="required">*</abbr></label>.
<span class="description">I agree
to the <a
href="https://adsler.co.uk/terms.
and-conditions/"> Terms and
Conditions </a> and <a
href="https://adsler.co.uk/
privacy-policy/"> Privacy Policy
</a> of Adsler.co.uk.</span></p>
</div></div>
<button class="btn button ur-
submit-button"
type="submit">Submit </button>
<div style="clear: both;"></div>
<input name="ur-user-form-id"
type="hidden" value="6456" />
<input id="ur_frontend_form_nonce"
name="ur_frontend_form_nonce"
type="hidden" value="82ebe8a59b"
/>
</div>
</div>
</form>
<div style="clear: both;"></div>
</div>
</div>
<!-- .entry-content -->
Ideally I'd like all content and files uploaded to Mysql to make it secure but, as I understand, Mysql doesn't handle images. So how to I do this, either by adding to WP files or another way but in any case securely?
Page:https://adsler.co.uk/dating
Providing full working code would be a lot of work, so here ill give you a idea on how to make that:
you store images in /images directory of your wp-installation
you need php to handle the Form (since you didnt provide any php-snippet, cant be sure if you got that)(This is a good Tutorial in my opinion)
Yeah this is secure (if the /images directory isnt public for the internet ofc)
I'm creating plugin in Wordpress with more steps form, and I would like to take some advice from you.
I've one function (using shortcode) with first form, after submit, I'd like to go on next step, but I don't know which solution is the best
My function:
function task_shortcode(){ ?>
<form id="form" action="" method="post">
<h3>Add new task</h3>
<div class="task-title">
<label>Title</label>
<input type="text" id="text" name="text">
</div>
<div class="task-description">
<label>Description</label>
<textarea id="desc" name="desc"></textarea>
</div>
<div class="task-new">
<input type="submit" id="create-task" name="create_new_task" value="Create new task">
</div>
</form>
<?php
}
add_shortcode('task_site','task_shortcode');
After that I want to go to another form and I dont know how to handle it. Using classic php action on submit button, or is there another solution?
I've found this, but I don't know if I can use it, because I want it to use on frontend.
https://www.sitepoint.com/handling-post-requests-the-wordpress-way/
Thanks for every advice
I have created one form to upload images for custom use
<form id="file-upload" action="" method="POST" enctype="multipart/form-data">
<div id="image-uploader-box" class="group">
<div id="forms" class="add-photo-fields">
<input type="submit" value="Upload" />
<input type="button" id="add-photo-button" class="add-photo-button" value="Add Photo"/>
</div>
</div>
</form>
Now it is working fine with uploading image and storing to proper place. But what I exactly want is auto submit above form when user submit WordPress comment. ( when user hit the submit comment button )
Can anyone help me for this? I am fine with jquery or php either way.
This is the place to go: http://api.jquery.com/submit/ (jquery's submit function)
When uploading files you can post to an iframe: How do you post to an iframe?
I have a form such that a list of questions with inputs is followed by an invitation to upload files if they have them.
I have avoided nesting forms by popping up the form containing the upload. The difficulty is that if they press submit on the Uploader form, it will process the upload on the destination page, and likewise if they hit submit on the rest of the form, the uploads are not submitted.
How can I do both at once?
My code:
<form id="questions" action="page2.php" method="POST">
Question 1 <input name="q1"/>
Question 2 <input name="q2" />
Have any files to add? <button id="upload-button">Upload</button>
<input type="submit" value="Submit Answers" />
</form>
<div class="hidden">
<form id="fileupload" enctype="multipart/form-data" action="uploader.php" method="POST">
<input id="fileupload" type="file" name="files[]" multiple>
<input type="submit" value="Upload Files" />
</form>
</div>
jQuery will pop up the hidden div if someone presses the button to add files.
I don't have a problem with them being posted to the same place, but I tried using javascript to use the click event for each button to submit both forms and it did not work.
(Reading stack overflow later explained that only the last submission gets processed in this way)
Any ideas? Thanks
Very simply, structure your HTML like this, and process the logic from both page2.php and uploader.php in one shot (i.e. include the file-upload logic in page2.php). If you show us the contents of both of those files, I can show you how to combine them.
Also added labels with links to the associated inputs, and swapped the submit input for a button element.
<form id="questions" enctype="multipart/form-data" action="page2.php" method="POST">
<label for="q1">Question 1</label>
<input id="q1" name="q1" type="text" />
<label for="q2">Question 2</label>
<input id="q2" name="q2" type="text" />
<label for="fileupload">Upload a File<label>
<input id="fileupload" type="file" name="files[]" multiple />
<button type="submit">Submit</button>
</div>
I have a confusion, i was going through a blog and in its comment it was suggested that target="_self" is vulnerable. It is true, if yes how we can fix it?
<form action="../process.php" method="post" name="login-form" target="_self">
<div class="FormItem">Username:
<span id="sprytextfield1">
<input class="textbox" type="text" name="text1" id="text1">
<span class="textfieldRequiredMsg">A value is required.</span></span>
</div>
<div class="clear"></div>
<div class="FormItem">Password:
<span id="sprypassword1">
<input class="textbox" type="password" name="password" id="password1">
<span class="passwordRequiredMsg">A value is required.</span></span>
</div>
<div class="FormItem">
<input name="login-submit" type="submit" value="SUBMIT">
</div>
</form>
it has nothing to do with security
the last time i used target, it was just to tell the form where the results are to be displayed, be it in the page itself, an iframe, or another frame in a frameset. as far as i know, it's pretty much useless.
here's a reference from sitepoint, indicating that "target" in forms are deprecated. (Hint: they died with Frameset)
The target attribute is deprecated, and, like the use of frameset for layout purposes, it’s no longer widely used. However, if you do find yourself having to maintain a frameset-based web site, you may wish to present the results of a form submission in a separate frame. For example, you might work with a two-framed page that displays the search form in the first frame and the search results in the second frame, refreshing only the results frame each time the form is submitted.
No target="_self" has nothing to do with it....