3

I know it is not possible for an html form to have two actions, but maybe there is a better way for me to accomplish what I need. I have a simple form that collects the users email address and signs them up for a Constant Contact email list. In addition, the email is submitted to another controller which displays a thank you message that contains the $email variable from the form. I can accomplish both of these things separately but cannot get them to work in sync with each other since the form information is being sent to thankyou() and the Constant Contact site. I'm sure there is a way for me to send this data to Constant Contact via the thankyou() controller, I am just not sure how to do that.

Also, I cannot use ajax with this because I need to show a different page on submit to track how many times the thank you page has been viewed.

Devin Young
  • 841
  • 7
  • 21
  • Could you make use of `$_SESSION` data for this? I believe codeigniter can create flash session data too, as in it is used once and then gets removed. – Dale Dec 06 '12 at 15:05
  • Can you show the code you're using for the constant contact submit? Because there is really no reason to use a second controller function or flashdata for this that I can see. When I create users I write to three models and MailChimp all from the same controller without issue – Rick Calder Dec 06 '12 at 18:05
  • In your _sign up_ --then-- _say hello_ case, you could simply redirect from one controller to the other. In a more complicated scenario you could setup multiple actions via ajax calls (client side javascripted). You can still navigate through other pages saving any ajax replies to the browser's localStorage. – Geo Halkiadakis Aug 19 '16 at 13:10

2 Answers2

1

Use flashdata, and store the email address in a flashdata variable.

$this->session->set_flashdata('email', $email);

Keep in mind that you will need to "keep" the flashdata if it is not used in the next request, otherwise it will disappear.

$this->session->keep_flashdata('email');

Then, set the $email variable for the view to $this->session->flashdata('email');

Brendan
  • 4,565
  • 1
  • 24
  • 39
  • This seems to be what I'm looking for! So I basically set the email address in $this->session->set_flashdata('emailAddr') and instantaneously pass this information on to constant contact? – Devin Young Dec 06 '12 at 15:12
  • What I would do is set the flashdata, submit to constant contact's API (that is what you're doing, right?) and then load the view containing the confirmation page. I'm not sure why you need the flashdata, but if you could give us more details as to the process you're currently using, that would be helpful. – Brendan Dec 06 '12 at 15:14
  • I was avoiding the API since it's a simple submit form and constant contact handles that well. That's when I run into the issue of submitting data to two different servers. I suppose this would just be much easier with the API wouldn't it? – Devin Young Dec 06 '12 at 15:21
  • Yes, in fact, I don't think flashdata will help here actually. – Brendan Dec 06 '12 at 15:32
  • Wound up not using the $email variable in the thank you page, wasn't entirely needed. Thanks for the help though, if I need it in the future I know what to do! – Devin Young Dec 06 '12 at 16:13
0

It should be something like this :- In view:

<form action="mycontroller/save">
</form>

In mycontroller:

public function save(){
  // Do whatever you have to do
  $this->session->set_flashdata('email',$this->input->post('useremail'));
  redirect('url to thankyou() controller');

}

IN thankyou controller:

public function save(){
  // Do whatever you have to do
  $email = $this->session->flashdata('email');
  $this->load->view('yourview',$email);

}
Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101