Issue url scheme of code-igniter - codeigniter

I have a form like
<form action="abc/1" method="post">
</form>
I want every time this form is submitted my URL remains same like suppose my current URL was
http://localhost/abc/1 after form submit it should be again
http://localhost/abc/1
but instead this it become
http://localhost/abc/1
http://localhost/abc/abc/1
http://localhost/abc/abc/abc/1 each time I press submit button in form.
its something related to URL schemes of mvc in code-igniter

The action of your form is relative to your current position.
If you are on http://example.com/contact and your form's action is set to contact/send the form well send to http://example.com/contact/contact/send Now, this would be easy fixed by either removing the contact/ part form the action attribute or by adding a / in the beginning of your action attribute, so the path is absolute - /contact/send.
Doing this in CodeIgniter should be relatively easy, as you can use the URL Helper to point to the correct URL's in your application.
<form action="<?php echo site_url('abc/1'); ?>" method="post">
</form>
This example will always point you to the page relative to your base_url and index_page settings in application/config/config.php.
In your case, mentioned in the comments, something along with <?php echo site_url('home/authenticateUser/' . $user_id); ?> would probably be the answer.

Try like
<form action="/abc/1" method="post">
</form>
or else you better to use site_url like
<form action="<?php echo site_url('abc/1');?>" method="post">
</form>

Changing the action from "abc/1" to "/abc/1" will work, but if you are building your app in a subdirectory, as is usually the case on a localhost development environment, this will revert to your htdocs folder, as opposed to your required folder.
I would recommend one of two options:
<form action="<?php echo base_url(abc/1); ?" method="post">
<?php form_open('abc/1')' ?>
Number 2 is the better one, as it works with CodeIgniter's CSRF functionality, and adds the base_url() automatically.
Hope this helps.

Related

WIX: Add custom HTML or my own form (to another website)

I need to create a form that by clicking on it will redirect to another website with special 'inputs' tags values.
something like:
<form action="http://example.com" method="post">
<input type="hidden" name="val1" value="something">
<input type="hidden" name="val2" value="else">
<input type="submit" name="submit" value="Go">
</form>
The custom HTML feature that I find will put it inside an iframe, and it looks bad. Is there a way to do it that will look 'normal'?
If you utilize Wix Code you can develop that inside your Wix page without the need of any html forms.
Simple solution:
- Add the form input elements you need on your page
- Add a button to click on
- Add av event handler to the button and grab the values from the input fields
- Send that data to any site or redirect the user to the site you want using wixLocation.to("url") with the query parameters you might need from the form.

CS CART call a controller at add on front end with microformat ajax

I am very new to cs cart. I have read their documentation about calling Ajax with form micrformats. I am able to create a Ajax request. But I would like to call a controller inside my add-on controllers/frondend/ directory names as mycheckout.php. I am using the a hidden file dispatch with the valu mycheckout.mymode. Can any one help me. I actually want to perform some action in my controller. But their documentation did not help me. Thanks in advance.
You can do something like this (use extra "cm-ajax-force" or "cm-ajax-full-render" classes if needed):
<form class="cm-ajax" name="your_name" action="{""|fn_url}" method="post">
<input type="hidden" name="result_ids" value="div_id_to_be_updated" />
{include file="buttons/go.tpl" but_name="mycheckout.mymode" alt=__("Ajax button")}
</form>
Or you can use any button you want (even <input type="submit" name="mychechkout.mymode" value="Ajax!">)
Note that the Ajax request can be also done via simple link:
<a class="cm-ajax cm-post" href="{"mycheckout.mymode?param1=value1&param2=value2"|fn_url}" data-ca-target-id="div_id_to_be_updated">Ajax!</a>

codeigniter 2.1.0 Routing difficulties

I can not load controller with
http://localhost/index.php?controller/method
But if i does not use '?' and try to load a controller from view then duplicate URL produce.
As an example of above, if i add this link in form action in view then result url will be
http://localhost/index.php/controller/index.php/controller/method
How to solve it? I did not use htaccess file
Use the site_url() function or, as #JohnFable stated, use the form_open function.
<form method="post" action="<?= form_open('controller/method'); ?>">
or
Controller/Method
or
<?= form_open('controller/method'); ?>
This will ensure that your "base url", i.e. http://localhost is prepended correctly to the URL you want to view, i.e. http://localhost/index.php/controller/method or if you have set it up to, http://localhost/controller/method
Gavin

Magento form post action to custom controller not working - wrong routing, but why?

I have a form in my Magento store, the contact form. When I navigate to the form, it has this URL: http://www.domain123.com/contact/. There is a form and it looks like this:
<form id="contactForm" method="post" action="contactform/index/sendcontactmail">
...
</form>
Now, when I click the send button, it gives me a 404 not found and I know why. The URL it posts to is http://www.domain123.com/contact/contactform/index/sendcontactmail, which is not right of course, it has to be http://www.domain123.com/contactform/index/sendcontactmail (without contact). The question is, how do I solve this issue? The contact form as the frontname contact and my modules name is contactform. How would I solve this?
Thanks!
Add a leading slash to your form:
<form id="contactForm" method="post" action="/contactform/index/sendcontactmail">
Or if working from a .phtml template the safer way is to use a bit of PHP. This will insert the correct domain:
<form id="contactForm" method="post"
action="<?php echo $this->getUrl('contactform/index/sendcontactmail') ?>">

Form action submit but NOT redirect (facebook static + magento)

This seems simple enough but there are complications...
I have a facebook FBML static page where I want users to sign up to my magento newsletter.
I think I'm right in saying typically you can put the form code as below into the fbml page and on submit it will add the user to the newsletter;
<form action="http://my-site.com/newsletter/subscriber/new/" method="post" id="newsletter-validate-detail">
<fieldset class="block-content">
<legend>Newsletter</legend>
<label id="newsletter-label" for="newsletter" class="left">Join our mailing list</label>
<div class="input-box left">
<input name="email" type="text" id="newsletter" class="input-text required-entry validate-email" />
</div>
<button id="newsletter-submit" type="submit" class="button btn-submit"><span>Join</span></button>
</fieldset>
</form>
But of course at my site I have an ajax function that returns a thanks for registering, so when this submit is sent from fb, this just lands me at a confirmation message on my domain that is supposed to feed through java and say thanks very much for signing up.
So what I need is some way of posting the action, but keeping the user on facebook, or at least leaving them at some other landing page after the action.
Something that posts but doesn't redirect, or something that posts then redirects to something other than the url in the form action?
Not sure if I need ajax for this or if js is even allowed within the fb environment, could I use any of their proprietary FBML to achieve this?
Many thanks
Could you add onSubmit="handleData(); return false;" to your form so it doesn't submit? and use the handleData() function to proccess the data in whatever way you need? This will keep the user from moving off the current page.

Resources