1

In native PHP I can include a javascript code to change the action of a form sent in case I need to direct the user to which page he selects to go like this

<form action="change.php" method="post" name="form">
<input type="submit" value="Click to Page1" onclick="form.action='page1.php';return true;"/>
<input type="submit" value="Click to Page2" onclick="form.action='page2.php';return true;"/>
</form>

I would like to do the same in case I must use codeigniter or cakephp. Someone could help me with this problem ?

Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96
user1125524
  • 9
  • 1
  • 3

1 Answers1

0

CodeIgniter is a backend technology. What you're writing is front end. You're pretty much all set; there isn't really much for you to change. You could, theoretically use CI's form helper, but it's unnecessary...personally, I never use it.

Unless you've removed the index.php file, change the form.action from page1.php and page2.php to index.php/mycontroller/myfunction.

The whole form idea though is sort of flawed; you don't really need it. Why not just use:

onclick="window.location.replace('index.php/mycontroller/myfunction');"

Then you can remove the form all together.

Community
  • 1
  • 1
Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96
  • What I learn from codeigniter is that whenever it needs to define a form, it writes something like =FORM_OPEN('FOLDER/METHOD_TO_CALL')?>, then I don't know how to do as my OP explained. – user1125524 Feb 09 '12 at 07:41
  • Second, I explain more...I have a form, after filling it in, it directs me to another form with 2 buttons, one of which redirects me to the previous form whereas the other will proceed further different action. That is what I am doing. – user1125524 Feb 09 '12 at 07:45
  • You're right, but that's the part of my answer that I said is not required. CodeIgniter has a lot of helpers and methods that don't really achieve much. What's wrong with the straight HTML? The CodeIgniter is going to produce it anyway. But if you need it... the form_open function takes the href as the first parameter. Just write = form_open('mycontroller/myfunction');?> and remove the above
    tag. See... you haven't really accomplished much. In fact you're called the PHP engine for something it shouldn't really have to think about... Additionally you can call form_close()...
    – Jordan Arsenault Feb 09 '12 at 07:48
  • Please redefine your actual problem, because even from the beginning it looks like you were in 'okay' shape. I gave tips of how to enhance what appears is already functional for you. – Jordan Arsenault Feb 09 '12 at 07:53
  • I don't understand anything you say. Could you produce me a small example using the source snippet as my OP above ? – user1125524 Feb 09 '12 at 08:10
  • 1
    I'm not providing an example until you've better defined your issue. Otherwise, I'll be stabbing in the dark all night. Do the forms actually have more inputs than the buttons themselves? If they don't and your goal is to direct your user to different forms then all of this could be accomplished with simple tags. You don't need the forms OR the javascript. – Jordan Arsenault Feb 09 '12 at 08:29