[eluser]felixk[/eluser]
I have two forms in one page, and when one of the forms have an error, that error is displayed in both forms.
Any ideas how to solve this?
If i shouldn't code in CodeIgniter i would just change name="submit" ...
This is the code for my to my controllers
Code:
function update()
{
$data['title'] = "GDI/Kundvagn - Webbshop | Hästtillbehör, båtlås, transportband";
$data['query_cat'] = $this->categoryModel->getAllCategories();
$data['myProduct'] = $this->productsModel->getProduct($this->uri->segment(3));
$data['error'] = '';
$this->load->library('form_validation');
$this->form_validation->set_rules('antal', 'Antal', 'trim|required|integer');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('buy_view', $data);
}
else
{
$id = $this->uri->segment(3);
$_SESSION['cart'][$id] = $_POST['antal'];
$this->load->view('buy_view', $data);
}
}
function buy ()
{
$data['title'] = "GDI/Kundvagn - Webbshop | Hästtillbehör, båtlås, transportband";
$data['query_cat'] = $this->categoryModel->getAllCategories();
$data['myProduct'] = $this->productsModel->getProduct($this->uri->segment(3));
$data['error'] = '';
//Kundvagnen
if(!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
}
$id = $this->uri->segment(3);
//Om buy-sidan har ett ID:
if(strlen($id) > 0)
{
//Om ID är en siffra
if(ctype_digit($id))
{
//Kolla om produkten finns
if(count($this->productsModel->getProduct($id)) > 0)
{
if(!array_key_exists($id,$_SESSION['cart']))
{
$_SESSION['cart'][$id]=0;
}
$_SESSION['cart'][$id]++;
}
// Om produkten inte finns, felmeddelande...
else { $data['error'] = "Felmeddelande: Felaktigt id för produkten."; }
} //Om ID är en siffra --> SLUT
else { $data['error'] = "Felmeddelande: Felaktigt id för produkten."; }
} //Om det finns något ID --> SLUT
//Contact form:
$this->load->library('email');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'lang:Namn', 'required');
$this->form_validation->set_rules('email', 'lang:E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('city', 'lang:Gatuadress', 'required');
$this->form_validation->set_rules('code', 'lang:Postadress', 'trim|required|min_length[5]|max_length[5]|alpha_numeric');
$this->form_validation->set_rules('phone', 'Telefonnummer', 'trim|required|alpha_numeric');
$this->form_validation->set_rules('url', 'Hemsida', '');
$this->form_validation->set_rules('business', 'Företag/Organisation', '');
$this->form_validation->set_rules('comment', 'lang:Meddelande', '');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('buy_view', $data);
}
else
{
$data['hej'] = "hej";
$this->load->view('buy_view' ,$data);
}
And here's parts of the viewer:
Code:
<form action="<?php echo base_url(); ?>gdi/update/<?php echo $row['prod_id']; ?>" method="post" name="products">
<td><?php echo $row['prod_number']; ?></td>
<td><?php echo $row['prod_name']; ?></td>
<td><input type="text" name="antal" value="<?php echo $antal; ?>" size="3"/></td>
<td><?php echo $row['prod_price']; ?></td>
<td><input type="submit" value="Ändra" /></td>
</form>
<?php echo validation_errors(); ?>
<?php echo form_open('gdi/buy'); ?>
<p><input type="text" tabindex="1" size="22" value="" id="name" name="name"/>
<label for="name"><small>För- och efternamn (behövd)</small></label></p>
<p><input type="text" tabindex="2" size="22" value="" id="email" name="email"/>
<label for="email"><small>E-mail (behövd)</small></label></p>
<p><input type="text" tabindex="3" size="22" value="" id="city" name="city"/>
<label for="city"><small>Gatuadress (behövd)</small></label></p>
<p><input type="text" tabindex="4" size="22" value="" id="code" name="code"/>
<label for="code"><small>Postadress (behövd)</small></label></p>
<p><input type="text" tabindex="5" size="22" value="" id="phone" name="phone"/>
<label for="phone"><small>Telefon (behövd)</small></label></p>
<p><input type="text" tabindex="6" size="22" value="" id="url" name="url"/>
<label for="url"><small>Hemsida</small></label></p>
<p><input type="text" tabindex="7" size="22" value="" id="business" name="business"/>
<label for="business"><small>Företag/Organisation</small></label></p>
<p><textarea tabindex="8" rows="10" cols="50" id="comment" name="comment">Valfritt meddelande</textarea></p>
<p><input type="submit" value="Skicka" tabindex="8" id="submit" name="submit"/>
</p>
</form>