This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ilan3853
ilan3853

I'm trying to create a form with 2 action buttons to submit with the ajax framework. All other input values are sent correctly, but the button does not get sent with the rest of the inputs.

<form id="wizard" data-request="Wizard::onWizardStep" data-request-update="'Wizard::steps': '#wizard'">
    {% partial 'Wizard::steps' %}
</form>

and in the step partial (depends on the output of the callback function, but basically it will output something like this)

<input type="text" >
<input type="checkbox" >
...
<button name="action" value="foo">do foo</button>
<button name="action" value="bar">do bar</button>

Trying to retrieve the action value in the callback function:

var_dump(Input::all()); // outputs everything except the action value
var_dump(post('action')); // null
var_dump(Input::get('action')); // null

What am I doing wrong?

Shahiem
Shahiem

Unfortunately, the same problem.

Daniel81
Daniel81

Why can't you name your buttons action1 and action2 then do a post check like:

$value = (post('action1')) ?: post('action2');

if you're only checking against 2 buttons and you know what the name attributes are?

Lukasz
Lukasz

The same problem. Any new idea?

Scott
Scott

Give this a try

<button data-request-data="name: 'foo'">do foo</button>
<button data-request-data="name: 'bar'">do bar</button>
Lukasz
Lukasz

It doesn't work. "data-request-data" works only with "form".

Daniel81
Daniel81

Try using the AJAX framework via JavaScript like so:

$(element).request('onFunction', {data: {name: 'foo'}});

The data-request handlers don't need to be in a form to work, but if you can't get them working inline, try using the pure JavaScript route

aleximong12425
aleximong12425

Scott said:

Give this a try

<button data-request-data="name: 'foo'">do foo</button>
<button data-request-data="name: 'bar'">do bar</button>

It' Works, Thank Scott

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.