Welcome Guest, Not a member yet? Register   Sign In
anchor function- how to pass 10 values back to controller class ?
#1

[eluser]cinewbie81[/eluser]
Hi all,

In a Email Setting Form i have 2 buttons:.
"SAVE" button -> anchor('email/save', 'Save')
"SEND" button -> anchor('email/send', 'Send')

I have 10 fields in my EMail Setting form as well. How can i pass these 10 fields value to my Email Controller class ? The url will looks weird if i do something like this:

"SAVE" button = anchor('email/save/field1/field2/field3..../field10');
"SEND" button -> anchor('email/send/field1/field2/field3..../field10', 'Send')

I know it can be done using post method if i have only 1 button. But now i have 2 buttons, i cant determine which one should i use : form_open('email/send'); or form_open('email/save');

Help !! Sad
#2

[eluser]gtech[/eluser]
have you thought about using session data?

see sessions documentation especially the Adding Custom Session Data section.

It saves you having to pass data around the urls

I am also sure you can have two submit buttons in one form.
#3

[eluser]cinewbie81[/eluser]
Yeh i can use two submit buttons in one form ..
but how can the system tell if user click "SEND" button it will execute form_open(’email/send’), and execute form_open(’email/save’) when "SAVE" button is clicked ??
#4

[eluser]schnoodles[/eluser]
You could always handle that in your controller like

[code]
if ( $this->input->post('save) )
// do this
else
// do that
[code]
#5

[eluser]cinewbie81[/eluser]
hi schnoodles, i guess u misunderstood what i said, let me explain in details:

Email controller
Code:
<?php
class Email extends Controller {

  function Emailsetting()
  {
    parent::Controller();
  }

  function save()
  {
    // Save 10 field values here    
  }

  function send()
  {
     // send 10 field values here
  }

}
?>


Email view form
Code:
<?php $this->load->view("header"); ?>

   <ul>
       &lt;?php '<li>'.anchor('email/save','<img src="../images/save.jpg" alt="Save" />', 'title="Save"').'</li>'; ?&gt;    
       &lt;?php '<li>'.anchor('email/send','<img src="../images/send.jpg" alt="Send EMail" />', 'title="Send Email"').'</li>'; ?&gt;    
   </ul>

// HTML Field 1, HTML field 2 ... HTML field 10

&lt;?php $this->load->view("footer"); ?&gt;

When user click at the save button, i want the system to pass the 10 field values to save function in controller
When user click at the send button, i want the system to pass the 10 field values to send function in controller

Solution:

a) Anchor function
anchor(’email/save/field1/field2/field3/../field10’)
anchor(’email/send/field1/field2/field3/../field10’)
Anyway, it make my URL looks ugly.

b) POST
we can call $this->input->post('field1') easily from our controller class, but in email setting form we don't know whether to use &lt;form method="post" action="http:/www.your-site.com/index.php/email/send" /&gt; or &lt;form method="post" action="http:/www.your-site.com/index.php/email/save" /&gt; as our form action in advance Sad

Any alternative way ?

Help !
#6

[eluser]xwero[/eluser]
If you want to save or send data it's best to use a post form. Instead of sending them directly to different functions give the buttons a name and set up your controller accordingly
Code:
//html
&lt;form action="/email" method="post"&gt;
&lt;!--fields --&gt;
&lt;input type="submit" name="send" value="send"&gt;
&lt;input type="submit" name="save" value="save"&gt;
&lt;/form&gt;
// controller
//validation rules
if(!$this->validation->run())
{
  // error
}
else
{
  if(!$this->input->post('send'))
  {
    // save code
  }
  else
  {
    //send code
  }
}
#7

[eluser]Référencement Google[/eluser]
Absolutely not sure about my answer, but maybe should you make some tests with serialize / unserialize?
#8

[eluser]cinewbie81[/eluser]
Hi xwero,

I do it according to your suggestion.
When user click at button 'save', it echo me the value <b>send_end</b>. (It suppose to be save_admin@yahoo.com_end
When user click at button 'send', it echo me the value <b>save_end</b>. (It suppose to be send_admin@yahoo.com_end
It seems to me that the system can't detect the value of emailaddres. Any idea ? Btw, following is my codes:





Controller class for email setting


Code:
&lt;?php>

class Emailsetting extends Controller {
    
    function Emailsetting()
    {    
        // Load neccessary helper file, library etc
        parent::Controller();
        $this->readContent();
    }

    function index()
    {
        $this->load->view('form_emailsetting', $data);
    }

    function validation()
    {
        if ($this->input->post('save')) {
            echo 'save_'.$this->input->post('emailaddres').'_end';
        } else {
            echo 'send_'.$this->input->post('emailaddres').'_end';
        }    
    }

}
?&gt;


form_emailsetting.php - Form for email setting

Code:
&lt;?php echo form_open('emailsetting/validation');?&gt;

<div class="form_content">
    <table id="emailsetting" align="center">
    <tr>
        <td>Email Address:</td>
        <td> &lt;input type="text" name="emailaddres" id="emailaddress_id" value="[email protected]" /&gt; </td>
    </tr>
    
    <tr>
        <td>
            &lt;?php
                echo form_submit('save', 'Save');
                echo form_submit('send', 'Send');
            ?&gt;
        </td>
    </tr>
    </table>
</div>

&lt;?php form_close();?&gt;
#9

[eluser]xwero[/eluser]
I see you don't close your form using an echo maybe that is the problem?
#10

[eluser]cinewbie81[/eluser]
Problem solved ..
Thanks a lot xwero .. i really meant it .. !




Theme © iAndrew 2016 - Forum software by © MyBB