samedi 11 avril 2015

Alpaca form submission, stay on same page

I am building a form with PHP and ALPCA (jquery,ajax). I am having trouble with file submitting and staying on the same page. I have tried the recommended techniques for doing as such with AJAX event.preventDefault();, also using hidden frambut with no success. My question is does the ALPACA package require a different method?


FORM SECTION



<script type="text/javascript">
$(document).ready(function() {
$("#form").alpaca({
"schema": {
"title":"User Feedback",
"description":"What do you think about this Speaker?",
"type":"object",
"properties": {
"email": {
"type":"string",
"title":"Email",
"required":false
},
"feedback": {
"type":"string",
"title":"Feedback"
},
"ranking": {
"type":"string",
"title":"Ranking",
"enum":['It is Great', 'Not so cool', 'Very poor quality', 'I think there may be a Privacy or Copyright issue'],
"required":false
}
}
},
"options": {
"form":{
"attributes":{
"action":"FORM.php",
"method":"post"
"target":"hiddenFrame"
},
"buttons":{
"submit":{}
}
},
"helper": "What do you think about this Speaker?",
"fields": {
"email": {
"size": 20,
"placeholder": "email not nessasary"
},
"feedback" : {
"type": "textarea",
"name": "your_feedback",
"rows": 4,
"cols": 40,
"helper": ""
},
"ranking": {
"type": "select",
"helper": "",
"optionLabels": ["It is Great", "Not so cool", "Very poor quality", "I think there may be a Privacy or Copyright issue"]
}
}
},
e.preventDefault();
});
});
</script>


PHP FILE



<?php

$file = "people.txt";
$feedback = $_REQUEST['feedback'];
$ranking = $_REQUEST['ranking'];
$email= $_REQUEST['email'];
$string = file_get_contents("/tmp/live-info");

$json = str_replace('***(', $callback, $string);
$json = rtrim($json, ')');

$json_a = json_decode($json, true);

$current_name = $json_a['current'][name];

$current_name .= "|$email|$ranking";

$feedback .= "|$current_name" .PHP_EOL;

file_put_contents($file, $feedback, FILE_APPEND | LOCK_EX);

?>


Thank You


Aucun commentaire:

Enregistrer un commentaire