Post extra string through ajax form validation script - php

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.

Related

Form check as a whole

Hello I'm trying to get back into coding and I've hit a problem that I need some help with. I've created a form with HTML5 so it has the built in required fields and i can get this to post to a database but I currently have the POST on a different page so that I can just have words saying Submit complete but currently you can just go to that submit page over and over and it will just send off blank fields to my database so I wanted to check the post as a whole to see if the whole thing is empty then not submit but I don't know if this is the best way to do it.
thanks if you need my current PHP just shout and ill put it on.
First of all validate your form fields with Javascript or Jquery validation for client side validation. Its very easy, you can use jquery validation plugin eg.
Jquery Form Validation
For Server side validation you can use php functions like isset($_POST['field_name']) and !empty($_POST['field_name'])
For PHP form validation please visit the link for reference : PHP Form Validation

Extra input with ajax in an existing form

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.

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.

Store form data into hidden field using Jquery?

I have a form that has a popup page with another form. In that popup form I want to take all fields filled out and store it in a single field in the main parent form via a hidden field. So that when the parent form gets submitted I can get all the fields via the hidden fields via php. How could I do that with jquery? Can I take all the fields from the popup form and store it as a json string in the hidden field? Then in php be able to turn that jquery string into an object so I can get easy access to all the form values? If so then how would I take all the fields from the popup form and turn it into a json string? Or is there a better/easier way?
To capture the form into an input for posting:
You want to .serialize() the form.
$('input').val( $('form').serialize() );
Then, in PHP, you just do a parse_str() to split it back up into an array.
Also, keep in mind that there may be a better solution than passing field data around like this, but if you're hellbent on that implementation, this is probably the way to go.
To open a form as a modal, then collect the data in PHP:
// You can set this to not open by default and bind the opening to a button, or a link, etc...
$('form').dialog({
modal: true
});
In PHP, your form will be contained within $_POST as normal.
print_r( $_POST );
One idea would be to use jQuery to create fields like this:
$(".innerForm input").each(function() {
$(".parentForm").append("<input type='hidden' name='"+$(this).attr("name")+"' value='"+$(this).val()+"'");
});
If you add the values to your page this way then you would just be able to access them as though they were normal parts of the $_POST
$_POST("hidden_field_name")

Pass data from javascript to PHP in cakephp

Hello I have a select element which has a few options. I am able to get the selected option when an onChange event is fired. Now I need to pass that option text to php, either with pageload or ajax.
echo $form->select('data_source_select',$dataSourceOptions,null,array('escape'=>false, 'empty'=>'Select One','onChange'=>'getData(this)'));
is my select form element, with its options being set in controller. Now onchange, I need to pass the selected option to php/action to load the data specific to this option search. Any help would be great.
Thanks.
As you said, you could either do this as a regular form submission, or as an Ajax form submission. My answer will focus on regular form submission, since Ajax will essentially work the same way and can simply be added on to enhance it later.
One quick solution is to add a hidden field to your form, maybe call it "step" and give it a value of 1. When the data source is selected, simply submit the form and check the value of "step" in your controller. If it is equal to 1, you'll know to load the data based on data_source_select. If the value of "step" is not 1, it indicates that you're on another step in the process and you don't need to process the data source value again.

Categories