I have a Parent/Child form. For example, the parent table may have the following field
Number of projects completed
Have you ever worked with our company? (Yes/No radio button)
If the second option have 'Yes' value, then I need to fill the details form.
For example: "The project name done with our company, copy of contract to be uploaded etc."
I have the following logic,
The deatils form may have a ADD button to add deatils records. I think I can store the details data in JavaScript arrays? Can I store the
<input type="file" name="file_to_upload" />
in arrays ?
Then on the submit button, send the parent and child deatils to the database.
Is there any other method to accomplish the task ?
Please see the screen snap
I can only add one detail records at a time. My question is, where should I temporarily store the deatil list ?
yes, you can store the details data in javascript but you have to put that details in the form somehow, unless you send it via Ajax, but I am not sure if you can hold the image with javascript and then send it.
I think that you can also try a html array form, if you want to add a detail then just add another input with javascript, I think it looks something like this.
<input name="detail[0]" type="text"></input>
<input name="detail[1]" type="text"></input>
you can read something more about this here: http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html.
Related
I have a form that i want to filled up by the end user in few steps.
in the first step i want to let them fill Name,Address,Mobile number.
And when click next button i want to appear another part of the form to fill the other details such as upload a image .
i did research online,i found 2 articles useful,
One thing is about sessions and the other thing is about hidden fields.
In my opinion i think sessions are not a good way to use for form submitting.Because some browsers are might have disabled sessions.
So ill go with hidden fields.
In my database i have a unique id which is auto increment.What i want to do is to let user to submit a form.In the first step i want them to submit their name,addres,mobile number(In this time it is inserting data to the database- Only for couple of columns.) And in my database i have a field for upload a image.In the first step it gets a null value.I want to update that null value in the next step by getting a that id from the first step
Please give me the basic idea to start this.A little help much appreciated!
Thanks in advance
you can try like this:-
You can add a class on the input which you want to hide
<input type="text" name="example" class="inputHidden">
after that add style in your page like this
<style>
.inputHidden{
display:none;
}
</style>
If you're trying to place the form data into new, hidden inputs - take the initial input.
<input type="text" name="example">
On the next page add a hidden input.
<input type="hidden" name="exampleP2" value="<?php echo $_POST['example']; ?>">
You can get form submited data and use it in input hidden fileds
for e.g. in first form you have
name ,email etc fields
in other form you have more fields
here you can use <input type="hidden" name ="firstname">
and thus you can add as many as you want
I'm building a virtual tour application and have hit a bit of a stumbling block during the setup process. Currently, the administrator is the one responsible for determining which stop belongs to which panorama as well as the choices for the next move. In order to complete this, I need to be able to insert the photo name into the database along with the other information of the current stop.
My form solution was to add the photo names of a certain directory into an array, count the number of images in the folder, and create the corresponding number of mini-forms on the page. Each form has its own save button that works via ajax, so all information is updated as the user works through the stops.
My issue has to do with adding the photo name via the submit process. The photo itself is not a user-defined field in the form, and I'm using POST to pass the variables to the insert function. Is there a way to include the filename in the $_POST array just before submission?
what you have to do its use a hidden input with the filename in the value attribute.
<input type="hidden" name="filename" value="the filename" />
also, you can add the filename as a parameter in the ajax call, but i think that the input its cleaner.
In HTML5, an input without name is also valid
e.g.
<input type="text" id="user" />
But what is the point if I cannot access the form element in my backend PHP code?
Not all input is used server-side. In many cases it's used for form submission via AJAX. Additionally, a JavaScript app can make use of user input without ever needing to use a form.
Click the "link" button on any question or answer here on Stack Overflow, you will see an example of an <input> without a name or associated form.
Granted, this particular input is created with javascript - but it's pretty common to see an input field or textarea for copy/paste purposes, for one example.
..and it's also useful for basically anything to do with javascript.
One non-AJAX example I am currently using:
I have a spreadsheet for several dollar amounts to be filled in. I use an <input> field with no name to display the total amount of each column with javascript. On the server side, I don't need a "total amount" field coming through, and I sure as hell wouldn't trust it. The real total amount is calculated on the server side based on the other inputs, but we still show it in real time on the front end for the user.
I am creating a site in PHP while storing my date in a MySQL database. I have already created my sign-up, login, logout portions, but I would like to make things more user friendly and add an area where people can change their user settings. Some of the settings that I would like for the user to be able to modify are as follows:
full name
email
age
gender
etc.
That being said, I would like for them to be able to fill out only the portions of a form that they would like to update. They should be able to leave everything else unchanged and submit all of their changes with a single submit button.
Any suggestions as to the best way to approach this problem are greatly appreciated.
As a side, I would eventually like for this site to contain AJAX (where the user might be able to select individual settings and change them at will), so if your solutions take that into consideration, that would be great.
EDIT:
Sorry, but I should have mentioned that I want to keep the information from being shown to the user (i.e. displayed in the text field) unless they explicitly type in there. As far as I can tell, this would keep me from always posting all of the data every time.
I have a great way of achieving this. Just simply do some if/else coding in php. Like this--
Html Code:
<form action="settings.php" method="POST">
<input type="text" name="full name" />
<input type="text" name="email" />
........ (and more)
</form>
And PHP code ---
<?php
if($_POST)
{
if(isset($_POST['full name'])) { //Update full name of user and redirect to the settings page on success. }
else { //Redirect and show errors! }
if(isset($_POST['email'])) { //Update email of user and redirect to the settings page on success. }
else { //Redirect and show errors! }
}
?>
Or you can use array function of PHP to set the MySql queries in it like ---
<?php
mysql_query("
UPDATE table name SET
//Loading different values from the array using foreach() php function.
");
?>
Just try to do some modifications in it.
Hope this helps you.
Your choices are:
1) multi-stage edit process. 1. pick fields to change. 2. present fields for editing. 3. save updated data. Rather tedious
2) present all the fields in a form, but use some Javascript to keep track of which ones were changed and submit only those
3). present all the fields in a form, and update all the fields in the database. if one or more weren't changed, the update is a null-operation anyways.
3)'s easiest to implement. 2)'s dependent on javascript. 1)'s tedious for you and even more tedious for the user.
As long as you do proper validation on all the fields, I don't see how #3 is anything but the most logical choice.
Create a edit.php or something else. Create textfields which one you want to edit.
All information could be showed thats related with the unique id of a user.
input type='text' value='"Example: Select * from users WHERE id = '$userid'"' name'Example: Update_name'
Do this for all the field you want to edit. After creating this edit.php. Use a script to update the $_POST or $_GET user details. Based on this easy to use script you've got a edit function for a user.
I'm setting up a contact form, but I have some saved information in some spans (It's an ecommerce shopping basket) and the built in checkout is awful so we're just slapping together an easy solution: turn it into an email form and email us the order instead of losing customers.
Anyway, can I use the info in the span, taking the id or name or do I have to turn it into an input? And if I do, how can I disable the input field?
Example of code I want to take into the email is in this jsFiddle, I want the spans with name="ACTUAL PRICE" etc emailed. Is this possible?
Thanks :)
Maybe you want to use a hidden input field.
<input type="hidden" name="key" value="foobar" />
It is not displayed, but can be used to submit information with the form.
You'd be far better off using hidden form fields if possible. Else if the user has JS disabled you may run in to issues down the line. Rare but possible.