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.
Related
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.
I have a simple lead collection form that asks for the user's zip code on the first page, and then based on which state that zip code is in it sends them to the second page of my form with the zip code already populated, or to another site. In my pre-CodeIgniter days this was a very simple thing to do, but I'm not sure how to send the zip code data from my routing script to the second page of my form and not have it mess with CI's form validation. The second page of my form currently looks like this:
<input type="text" name="zip"value="<?php echo set_value('zip'); ?>" />
So if the user submits invalid data on the second page, the form reloads with all the data pre-populated (using CI's set_value function). But what needs to happen is something like...
IF the user comes from page 1 of the form, populate the zip code field using the data from form 1. ELSE, re-populate it after a failed form submit.
Is there some way for set_value to intelligently work in both situations? If not, do I need to use a different function? I'm also not sure how to pass the zip code data from my routing script to the controller for page 2 of the form.
I'd really appreciate any help. THANK YOU!!
I'm just trying to understand the submit button within php.
I know that it performs that action stated within the form tag. So basically what I have is an form tag that only defines it's ID, i.e. no method attribute nor action. And within this form is a submit button. This input element only defines the type as submit, i.e. no name attribute nor id nor value.
Quickly describing the file: It has two input text elements which are required and a submit button. When i view this file in chrome, and i've clicked the submit button, a pop up shows below the required fields which i have not entered text in stating "required field".
I love this function however, it doesn't check for spaces, i.e. " ".
So back to my question, could someone possibly tell me what the submit button actually does or possibly what methods does it call when i click on it even though the form it is in has no action defined.
When the button is clicked, the browser detects this and submits the form back to the server. This has nothing to do with PHP, it's simply the browser implementing what the HTML specification stipulates.
Since your form does not have an action attribute, what happens is that the browser gathers the values of all eligible input controls in the form, turns that into a query string and makes an HTTP GET request to the current URL using that query string. The HTML5 spec covers this in detail.
The submit button offers one possible interface for the submission of the form. It's like the send button for a text message. While there are alternatives to submit the form, the submit button is the HTML option.
When a form's action is empty, the form submits the GET data to the page that form is on. (Basically, it reloads itself, with the new form data attached.) So you could write your PHP code at the top of the same page to manipulate the data.
In your PHP code at the top of the page, you can test whether or not your form sent data in those two required fields. If one or both are empty, you can echo a message to the user telling them the fields are required.
When user create a post, inside the post form, I want to provide a button. When user click the button, it will launch an iframe and submit some of the inputs of the post form. When nested form is not valid, how can I submit those inputs to the other website?
Two methods, Javascript, and PHP
Javascript:
You can use jQuery Post to do this by javascript.
Basic steps:
Use an "onsubmit" handler for the form
In the function for handling the submit, build a data array with data you want to submit and send to the second form.
Either return true (to allow the programmed submit to continue) or build a secondary submit if required.
This one allows you to build the validation you refer to client-side (i.e. in the submit handler).
PHP
Receive the data in the php form, then use CURL in the receiving PHP script to pass data as needed to the second form.
I'm making this contact form. The site itself uses AJAX to load the content in the main window. The problem with my form is that when the user clicks on submit and the data passes validation, it loads the page to main instead to itself to reach the actual mailing script.
Is there any way to pass this??
take the action our of the form opening tag
If you're using the Prototype.js library, you could just call event.stop() on a passed event object, on form submit.