Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML POST form submit is mangling URL
    primarykey
    data
    text
    <p>I am trying to get a HTML/PHP form to submit properly. Some details:</p> <p>base url = <code>http://localhost/directory</code></p> <p>page = <code>page/add</code></p> <p>complete address = <code>http://localhost/directory/page/add</code></p> <p>Using htaccess to rewrite urls so <code>http://localhost/directory/page/add</code> is actually <code>http://localhost/directory/index.php?q=page/add</code></p> <p>My HTML POST action is "page/add" so that the front controller knows which function to fire to sanitize and submit the data (it acts as a 'form id').</p> <p>The page loads fine at <a href="http://localhost/directory/page/add" rel="nofollow">http://localhost/directory/page/add</a> but when I click on the submit button, the URL gets mangled to page/page/add. And every time I press "submit" I get another "page" added to the url. So 5 clicks will get "page/page/page/page/page/page/add"</p> <p>I can't seem to find why I am getting that "extra" "page".</p> <p>The actual PHP error (page/page/add doesn't exist in $routes since it isn't a valid route):</p> <p>Notice: Undefined index: page/page/add in C:\xampp\htdocs\script\includes\common.inc on line 92</p> <p>Here is the function at line 92:</p> <pre><code>function route_path($path = NULL) { $routes = get_routes(); //Returns array: approved "urls =&gt; function callbacks" if($path === NULL) { $path = get_path(); //Returns $_GET['q'] with trim and strip_tags } $function = $routes[$path]; &lt;&lt;&lt;&lt;&lt;----This is LINE 92 if(isset($function)) { $form_name = str_replace('/', '_', $path); // page/add = function page_add() } if(function_exists($function)) { call_user_func($function, $form_name); } else { //TODO: Redirect to Login screen. } } </code></pre> <p>The basic HTML is:</p> <pre><code>&lt;form action="page/add" method="post" /&gt; //Form elements &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>Thanks for the help.</p> <p><strong>UPDATE</strong>: What I did was add the <code>&lt;base&gt;</code> tag to my HTML templates. This allows me to keep the action as page/add (since it is also a route in my simple router/dispatcher).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload