Welcome Guest, Not a member yet? Register   Sign In
Loading a Preview before sending a Newsletter
#1

[eluser]AlphaGirl[/eluser]
Hi,
i'm organizing a form where the user can build a Newsletter, title, message, and uploading a file.
Ok, the problem is not about the code to get it done but i'd like to keep the structure clean, clear etc..
How can i swich from
Code:
action="controller/preview"
to
Code:
action="controller/send"
based on the button the user would click on?
I mean, i don't wanna send values to another function
Code:
eg: controller/check
that would switch between them, coz after that i'd have a longer slug on the url:
Code:
www.mysite/newsletter/check/preview
or
Code:
www.mysite/newsletter/check/send
but also because i wanna keep code as
separate, readable, easy as possible..
Hope i'm not confusing you.. :-)
#2

[eluser]rana[/eluser]
Well, you will need help of javascript then. Here is a sceudo code I would use:

Code:
<form action='' >
...... your form code

<input type = 'submit' value = "send"  onclick= 'this.form.action = news/send' />
<input type = 'submit' value = "preview"  onclick= 'this.form.action = news/preview' />
</form>

Hope this will do your work. Thanks.
#3

[eluser]AlphaGirl[/eluser]
Yes,
this could be a solution,
i don't wanna be fussy coz you for sure you know programming better than me,
but what if (rarely) js is not enabled or would it be safe for a frontend application?
I mean with firebug you can easily change the action of a form.. Sad
Maybe after that i should check inside my functions that data are safe, right?
Thanks a lot for you attention and patience.. Smile
#4

[eluser]CroNiX[/eluser]
I'd just have 2 submit buttons with different names, then in the controller check which one was used.

Code:
<input type="submit" name="preview" value="Preview">
<input type="submit" name="send" value="Send">

Code:
if ($this->input->post('preview') !== FALSE)
{
  //do the preview
}
#5

[eluser]AlphaGirl[/eluser]
Dear Cronix, you believe i can do something like below or i don't necessary need to use functions
inside controllers? Can load function from inside if else like the code below?
When i point to this controller without specifying a function won't it look for
the index() function? Shoud i maybe put this code before the index?
Code:
if ($this->input->post('preview') !== FALSE)
{
  function preview() {
   //do the preview
} elseif ($this->input->post('send') !== FALSE)
{ function send() {
   //do the send
}
}

Thanks a lot!! Smile
#6

[eluser]AlphaGirl[/eluser]
Found a solution, should be quite safe and clean code, isn't it?
Code:
function newsletter_check()
    {
      if($this->input->post('send') ==! FALSE):  
                switch($this->input->post('send')) {
                    case 'send':
                         // send newsletter email
                        break;
                    case 'preview':
                          $data['title'] = $this->input->post('title');
                          $data['message'] =$this->input->post('message');
                          $this->load->view('admin/preview_view', $data);
                        break;
                }
      else:
          die('Something is wrong!');
      endif;  
        
        
    }
#7

[eluser]Otemu[/eluser]
Hi,

You could do something like this
Code:
function newsletter_check()
    {     switch($this->input->post('send')) {
                    case 'send':
                         // send newsletter email
                        break;
                    case 'preview':
                          $data['title'] = $this->input->post('title');
                          $data['message'] =$this->input->post('message');
                          $this->load->view('admin/preview_view', $data);
                        break;
                    Default:
                        //some default code here
  }
Be nice to have a save functionality too.
#8

[eluser]AlphaGirl[/eluser]
Hi Otemu,
It looks even more clear, and i love clear code.
So Default comes if there is not match from case to case inside a Switch? (i'm not a Php guru Smile
I'll try it!
Thanks a lot.
#9

[eluser]Otemu[/eluser]
[quote author="AlphaGirl" date="1361551145"]Hi Otemu,
It looks even more clear, and i love clear code.
So Default comes if there is not match from case to case inside a Switch? (i'm not a Php guru Smile
I'll try it!
Thanks a lot.[/quote]

Yes that correct




Theme © iAndrew 2016 - Forum software by © MyBB