POST request with ajax and jquery serialize() lost values
<p>I'm trying to retrieve four values from a post request but I only get 2 of them. The form contains an id, step, name, and email but I only get the ones from the hidden inputs. And not the ones that the user fills in. I think that it might be the jquery <code>serialize()</code> but i'm not sure.</p>

<p>I have tried to change the inputs to hidden and then add value="something" and it works. Why doesent it work with regular text?</p>

<p>//result from post request:</p>

<pre><code>[position_id] =&gt; 229
[step] =&gt; 1
[name] =&gt; 
[email] =&gt; 
</code></pre>

<p>The form looks like this:</p>

<pre><code>&lt;form id="referral-form" action="#" method="post"&gt;

    &lt;input type="hidden" name="position_id" value="{{$position-&gt;id}}" /&gt;
    &lt;input type="hidden" name="step" value="1" /&gt;

    &lt;div class="form-group"&gt;
        &lt;input name="name" class="form-control" type="text" id="name" required/&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        &lt;input name="email" class="form-control" type="text" id="email" required /&gt;
    &lt;/div&gt;
    &lt;div id="legal"&gt;
        &lt;span class="loader-button"&gt;&lt;/span&gt;
        &lt;div class="button submit"&gt;&lt;/div&gt;
    &lt;/div&gt;

&lt;/form&gt;
</code></pre>

<p>I have a javascript method that get initiated if user clicks on <code>.button.submit</code></p>

<pre><code>onRef: function(e) {
    e.preventDefault();
    var $form = $("#referral-form");

    if(!$form.hasClass("ajax"))
    {
        $form.addClass("ajax");
        $form.find('.error').css('display', 'none');

        var req = $.post('/reff/ref', $form.serialize());

        req.done(function(res) {
            $form.removeClass("ajax");

            if(res.success) {
                //do somthing
            }
            else {
                methods.printErrors(res.errors, $form);

                mixpanel.track('onReferralValidationFailure', {
                    errors: res.errors,
                    positionId: exported.position.id,
                    companyId: exported.position.company_id
                });
            }
        });

        req.fail(function() {
            $form.removeClass("ajax");

            mixpanel.track('onReferralUnknownError', {
                positionId: exported.position.id,
                companyId: exported.position.company_id
            });
        });
    }
},
</code></pre>

<p>And when I try to retrieve the post data within the /reff/ref function in php I only get this data. </p>

<pre><code>[2016-07-07 11:58:39] local.INFO: Array
(
    [position_id] =&gt; 229
    [step] =&gt; 1
    [name] =&gt; 
    [email] =&gt; 
)
</code></pre>

<p>This is the function in reff/ref:</p>

<pre><code> public function refer() {
    $positionId = Input::get("position_id");
    Language::setLanguageByPositionId($positionId);

    if(Input::get("step") == 1) {
        $validator = new ReferralStepOneValidator(App::make('validator'));
        $validator-&gt;with(Input::all());

        Log::info(print_r(Input::all(), true));

        if($validator-&gt;passes()) {
            $input = Input::all();


            $referral = Referral::createReferralFromInput($input);

            return Response::json(array(
                'success' =&gt; true,
                'reference' =&gt; $referral-&gt;reference,
            ));
        }
        else {
            return Response::json(array(
                'success' =&gt; false,
                'errors' =&gt; $validator-&gt;errors()-&gt;toArray(),
            ));
        }
    }
</code></pre>