Extra input with ajax in an existing form - php

I have a big form and there are lots of inputs in it (about 15 inputs ).
I made it with normal submit type style with Laravel. I send my inputs to Controller to fetch and save them. But now I want to add extra multi-upload input(for some pictures) at the end of my form.
I tried some nice-looking jquery plugins, but I couldn't achieve anything.
I send my inputs the normal way, but these jquery plugins are using ajax methods. I have one controller to save my inputs and when I write a new controller for ajax method, it saves into a new row in database . So my inputs and upload input don't match each other
What should I do ?
Is there any solution for saving them in the same place or should I handle the entire form with ajax ?
Or is it possible with a multistep form , in first form i can take normal inputs and in second form i can do ajax implementions.

Related

dynamically filled forms with Jquery & Ajax

I have a bit of a problem achieving what I'm trying to do.
I'm doing a mailbox like page and I'd like to add a "Respond" button which will fill a form with some values.
I'm generating my page message by message in php. For each message I generate an input button with its own id and when I click on the button, I'd like to open a form in a new window, with the recipient and title prefilled and not changeable by the user, with another textarea that the user can fill with his message.
For that, I have a general template for a form containing 3 values (recipient, title and message). All are (for the moment) text or textarea values.
Is it possible to use one form to send a message to anyone, or do I have to generate a form for each message with pre filled values ? The last solution seems quite horrible to do.
I tried to find something that I could do with only javascript, since I want the form to be submitted asynchronously by Ajax.
I can make an onClick event and pass the values to that function, but in that case I won't have the values of the textarea the user will have entered.
Is there a way to do, for example, an entire form in Javascript with the values I'll pass through the onClick event, get the value of the textarea from the form that would have been populated with these values, and then send everything through Ajax ?
Well, here is what I did.
For each Respond button generated, I set an onClick event passing the fields I wanted to be pre-filled in my form to a JS function RespondMessage()
I also made a form at the bottom of my page that I hid with css.
This form contains as much hidden fields as I want pre-filled datas, and as much spans as I want to show infos.
When I call the RespondMessage function, I manually set the hidden fields in my form with the arguments I called the function with.
After that I fill my spans with the infos I want to show (for example, I set the recipient's name for my message like that).
Once all of that is done, your form is ready to be displayed. So after setting the fields in the form, I just pass the form from display:none to display:block, and do a lot of css tricks to make that smooth and beautiful.
So now you have your pre-filled form, you just need another function that will make an Ajax call to avoid reloading the page after each response, and you'll call it with the onClick event of your form's submission button.
I hope that this process will help someone.
I'm not quite sure that it's the best way to do it and I find it quite dirty and exploitable so you need a bit more server side checking than usual, but it does the job.
I don't provide code because it's mostly all really specific to the application you're setting up.

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.

Connecting forms in php

I have a form which has details like name,number,email,etc... I have 3 forms like this.
So I have created a file called form.php which has the form and I am including it in my page.
Each of the form has some details that is not in the other forms like:
One form has Number of slots while the other 2 don't have it.
I explicitly added the uncommon part of the form in each page differently as a form.
Now I have 2 submit buttons. So how do I avoid two buttons and connect the 2 forms as the data from the complete form? It has to added to a single table.
Use $_SESSION in the first 2 forms to get the data to the third form.
http://php.net/manual/en/reserved.variables.session.php
Then retrieve data from the session in the third form and place it as a hidden field.
Then the submit button on the last form will submit all the data i.e from the fields in the third form as well as the data carried from the first two forms.

Post extra string through ajax form validation script

I am trying to pass a custom variable and value through ajax when the form submission event starts, they have this option when you validate field on blur but when the form is submitted I don't see how to add custom variable to this.
This what they have in on blur validation jquery.validationEngine-en.js
"ajaxUserCall": {
"url": "ajaxValidateFieldUser",
// you may want to pass extra data on the ajax call
"extraData": "name=eric",
but there are no options for form submission.
Maybe someone can take look at script and tell me how can i add extra variable with the form?
The demo is here
The script is here
Settings for script
The home page is here
Separate extra Post data with the & separator. For example:
name=eric&this=that&lastname=johnson
It's the same way you add extra GET data in a plain php/html form, except with ajax you pass post data the same way. Was this your question? Maybe I misunderstood.

Adding form elements to a form powered by Zend_Form

I have a huge and complex form, and I have build it using Zend_Form.
There are multiple places in the form where the user can add elements on click.
Currently, if the user submits the form, and the validation fails - the elements added by the user are not retained - as they were not a part of the form.
Is there a natural way to add them as a part of the form [emphasis on natural]?
Presumably you are adding new elements to the form using Js.
So you should use Js to populate some hidden field with information about what the user has added to the form. When the form is submitted read in this data and automatically re-add those form elements.

Categories