This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
There is a good example given in the default installation.
- See the page AJAX framework. Look at markup and code section.
- See the partial "calcresult"
Anyhow, here is a more brief howto example based on the above
Step 1: place your form code in the markup area like this
<form data-request="onTest" data-request-update="calcresult: '#result'">
<input type="text" name="value1">
<input type="text" name="value2">
<button type="submit" data-attach-loading>Calculate</button>
</form>
<div id="result">
{% partial "calcresult" %}
</div>
- The data-request="onTest" within the form tag is required for the php code. But you can use a name you prefer, but it has to start with "on..." (so "onHavingFun" would do it too)
- the data-request-update="calcresult: '#result' " is required for place where the results have to be shown.
- The div with id="result" is where the results are displayed
- The name "calcresult" in the form tag refers to a partial called with: twig {% partial "calcresult" %} It is called for display (but you can choose any other name too)
Step 2: place your php code inside the code section. Notice: you have to write your code inside a function named as described in the form tag (eg "onTest" or "onHavingFun")
function onTest() {
$value1 = input('value1');
$value2 = input('value2');
$this['result'] = "Your input was: " . $value1 . " and " . $value2;
}
Step 3: finally create a partial named calcresult an place the following twig code into the markup section:
{% if result %}
{{ result }}
{% endif %}
The twig expression {{ result }} displays what is defined in the php code as variable $this['result']
Got it?
Cheers!
Oskar
P.S. sorry for the missing idents and bad formatting of the souce code sections. To my opinion the markup implemented here is a little bit complacated and the preview does not fit the final view.
Last updated
oskar.villani40843, may be you help me more? how to send POST inputs to Mail without Ajax?
Last updated
1-5 of 5