Codeigniter submitting form1 form2 on form_open - codeigniter

any idea how to handle this problem ? my problem is when i submit on form2 the form1 automatic submit to. I want is when i submit on form2 only the form2 submit it. Please check this sample code.
<?php echo form_open('form1'); ?>
<input type="text" name="name">
<?php echo form_open('form2'); ?>
<input type="text" name="note">
<input type="submit" value="button2"> // this form2 is to insert note on this day
<?php echo form_close(); ?>
// then under this form2 we have a table. Table for list of note that all ready insert.
<input type="submit" value="button1"> // this form1 is to save all. the "Name" and also the note that we insert it on form2
<?php echo form_close(); ?>

I don't think it is a good way of programming to nest the forms.But after doing bit research for your question found this link which can come to your help.Click here
Hope that will work for you.All the best!

Change your nested submit element to
<input type="submit" name="form2_button" value="form2_submit"/>
Then, you can check the inner form submission using
if(isset($_POST["form2_button"]))` or in codeigniter you can input->post('form2_button')
Having a form nested under another form is not a valid HTML/XHTML. But you can try the follow code above.

Related

Cannot get the data in another page in CI

I have form and when i submit that data are passed to next page i can see that in url. but i when i get and print that it shows nothing , here i have attached my coding
<form action="addfilters/add"><input type="hidden" name="id" value=<?php echo $filters->id ?> > <input type="submit" value="Add New"></form>
my controller
<?php
class AddFilters extends Admin_Controller
{
function add(){
echo $this->input->post('id');
}
}
URL
http://localhost/code/index.php/admin/addfilters/add?id=1
but when i print ,it shows nothing , please help me
i have just used
<?php echo form_open_multipart('admin/addfilters/add'); ?>
top of the form. it works fine :-)

joomla module development with form - how to process

I'm creating a simple Joomla 2.5 module that will have an html form.
mod_mymodule/tmpl/default.php:
<form method="post" id="myemailform" action="">
<label for="ReferralName">Enter Name:</label><input type="text" name="name" value="<?php echo modCamcloudReferralHelper::getReferralName(); ?>">
<label for="ReferralEmail">Enter Email Address:</label><input type="text" name="email">
<label for="ReferralMessage">Enter Message (optional):</label><textarea class="message"></textarea>
<span class="countdown"></span>
<button type="submit" value="Send Email">Send Email</button>
<?php echo JHtml::_('form.token'); ?>
</form>
I have a helper class at:
mod_mymodule/helper.php - this just has some utility functions in it.
My question is what is the usual convention here to process my form on the server side. I tried to find examples of what people have done but I can't seem to find anything. Do I just put everything in the helper class:
<form method="post" id="myemailform" action="..\helper.php">
Or something like that? Thanks in advance.
Yes, you should do form processing in module helper class. Keep any logic out of the template file, and you can use mod_mymodule.php to call helper methods and assign variables before including the view file.
Do not set as form action helper file! I think in your case action should be the same page, so you can also ommit action url.
Edit: As requested in the comments, this would be the content of your mod_mymodule.php
// include helper file
require_once dirname(__FILE__).'/helper.php';
// call some method of the helper class
$items = modMymoduleHelper::getItems();
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
// render view file from mod_mymodule/tmpl/default.php, $items is available in the view file
require JModuleHelper::getLayoutPath('mod_mymodule', $params->get('layout', 'default'));

How to pre populate my custom form in magento

I've created a custom form, similar to a customer registration form, in Magento.
i want to prepopulate this form when an error messages arises.
Does anyone know how I can prepopulate a custom form in Magento?
Without seeing you code it is hard to say which method will method will work, but one of these method should work.
Using JavaScript Validation - client side validate, only post if all require info is correct
<form name="my-form" id="my-form" method="post">
<label for="username">
< ?php echo $this->__("User name") ?> <span>*</span></label><br />
<input type="text" id="username" name="username" class="input-text required-entry"/>
.....
</form>
<script type=”text/javascript”>
//< ![CDATA[
var customForm = new VarienForm('my-form');
//]]>
</script>
See a list of all the validation class name
Repopulate field
To get a list of all the post variable information that the customer fill out
Mage::app()->getRequest()->getPost();
To get a form field (eg. <input type='text' name='firstname' ... />)
Mage::app()->getRequest()->getPost('firstname');
So in you .phtml try (this will not work if you doing a redirect on error)
<input type='text' name='firstname' value="<?php echo Mage::app()->getRequest()->getPost('firstname');?>" />
If the above doesnt work then you need the save the post info into a session.
In your controller if validation fail save the information to customer session
Mage::getSingleton( 'customer/session' )->setData( 'yourFormName', Mage::app()->getRequest()->getPost() );
In your phtml template, print the data if 'yourFormName' variable session exist.

Loading a codeigniter view with a form from inside another view

Using codeigniter, I've been trying to load a view inside of a foreach loop, as follows:
$posts = $this->postslibrary->getAllPosts();
foreach($posts as $post){
$home['content'][$i] = $this->load->view('post', $post['data'], true);
$i++;
}
$this->load->view('head');
$this->load->view('home', $home);
$this->load->view('footer');
Each of those post views looks a little like this:
<div class="postnum<?=$post_num?>">
<p>Posted by: <?=$poster_name?></p>
<p>Reply to: <?=$poster_name?></p>
<form>
<input type='text' />
<input type='submit' />
</form>
</div>
And they're being loaded mostly successfully in the 'home' view (which is below for thoroughness).
<div ="posts">
<?php
for($i=0;$i<$count;$i++)
{
echo($content[$i]);
}
?>
<div class="clear"></div>
<a href='/posts/browse/'>Load more items</a>
</div>
But my output ends up looking like:
<div class='posts'>
<div class='postnum1'>
<p>Posted By: Jim</p>
<p>Reply to Jim</p>
<input type='text' />
<input type='submit' />
</div>
</div>
Why are my form tags not coming through?
Check if you already have a form around the current form. Chrome is one of the browsers which doesn't accept this and removes the second form. Using a form in a form is bad practice and I suggest you find a different solution to do the form handling.
Slightly left-of-field answer, but have a look at CodeIgniter Form Generator. I've used it a couple of times and it seems pretty good for generating forms from an array. It's a bit tricky to get your head around it to begin with, but it works well once you've gotten into it.
The basic idea is that you implement a form controller from your ordinary controller, and then just output it in your view file. It might be a more elegant (and sustainable) solution to what you're trying.

Suggest an AJAX solution to form submission without reloading page, with action="" instead of action="response.php"

I have a search page: (please excuse the bad syntax, just for demo purposes)
<form action="" method="post" name="form">
//form elements and such with a hidden input name="action" value="search"
</form>
<?php if(isset($_POST['action']) and $_POST['action'] == 'search'): ?>
<?php include results.php ?> //takes form data, build SQL query, puts results in array
<?php foreach($results as result) blah blah //for each result display it ?>
<?php endforeach; ?>
<?php endif; ?>
I've seen solutions where the action attribute is set to a php file. Unfortunately in my example it doesn't have one. Take this one: http://www.simonerodriguez.com/ajax-form-submit-example/
<form name="MyForm" action="response_ajax.php" method="post" onsubmit="xmlhttpPost('response_ajax.php, 'MyForm', 'MyResult', '<img src=\'pleasewait.gif\'>'); return false;">
It looks nice but unfortunately I don't have the first parameter required: reqsponse_ajax.php, mine is just blank.
The JS can be found here: http://www.simonerodriguez.com/wp-content/plugins/downloads-manager/upload/ajaxsbmt.js
If anyone can make modifications to the script or suggest a better solution, that'll be awesome, thanks.
it shouldn't matter at all what's in the action attribute when you're using AJAX. it's the onsubmit or the submit button's onclick attribute that starts the AJAX processing.
you do understand the basics of AJAX, right? instead of actually submitting the form, which would load a new page, you send an XMLHttpRequest to the server, POSTing the data, and wait for an answer back with onreadystatechange, at which point you dynamically update your page. there are literally hundreds if not thousands of examples of this on the web.

Resources