Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have ran into this when doing ajax forms where I include multiple field sets. Taking for example an employment application. I start out with one professional reference set and I have a button that says "Add More". This does an ajax call with a $count parameter to include the input set again (name, contact, phone.. etc) This works fine on first page call as I do something like:</p> <pre><code>&lt;?php include('references.php');` ?&gt; </code></pre> <p>User presses a button that makes an ajax call <code><code>ajax('references.php?count=1');</code></code> Then inside the references.php file I have something like:</p> <pre><code>&lt;?php $count = isset($_GET['count']) ? $_GET['count'] : 0; ?&gt; </code></pre> <p>I also have other dynamic includes like this throughout the site that pass parameters. The problem happens when the user presses submit and there is a form error. So now to not duplicate code to include those extra field sets that where dynamically included, i created a function that will setup the include with the appropriate GET params.</p> <pre><code>&lt;?php function include_get_params($file) { $parts = explode('?', $file); if (isset($parts[1])) { parse_str($parts[1], $output); foreach ($output as $key =&gt; $value) { $_GET[$key] = $value; } } include($parts[0]); } ?&gt; </code></pre> <p>The function checks for query params, and automatically adds them to the $_GET variable. This has worked pretty good for my use cases.</p> <p>Here is an example on the form page when called:</p> <pre><code>&lt;?php // We check for a total of 12 for ($i=0; $i&lt;12; $i++) { if (isset($_POST['references_name_'.$i]) &amp;&amp; !empty($_POST['references_name_'.$i])) { include_get_params(DIR .'references.php?count='. $i); } else { break; } } ?&gt; </code></pre> <p>Just another example of including GET params dynamically to accommodate certain use cases. Hope this helps. Please note this code isn't in its complete state but this should be enough to get anyone started pretty good for their use case.</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.
    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