New films will refresh when the submit button is pressed after the range slider has been moved (Laravel)












0














I am building a web application that will show a variety of films on a site. As part of this project I have some range sliders that can be moved depending on the mood you are feeling. If someone is to move the slider and press submit, I am wanting a fresh new list of films to displayed.



This is where I am having issues, I am able to display a set amount of films on the page but can't figure out a way to refresh the films once I click the submit button after moving the sliders.



Code Below




Upload (view)




<link rel="stylesheet" href="CSS/app.css" type="text/css">
<meta name = "viewport" content="width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://www.w3schools.com. /lib/w3.css">
<!DOCTYPE html>
<html>
<head>
<title>Moodslider</title>
</head>
<body>

<!-- Sky logo + Sky cinema logo -->
<div class="box">
<td style="text-align:center;color:black;font-size:50px;">
<img src="/images/sky.png" title="Sky" alt="Sky" width="auto" height="125" />
</td>
<td style="text-align: right;position: relative; color:black;font-size:50px;">
<img src="/images/sky_cinema.png" title="sky_cinema" alt="Sky" width="auto" height="125" />
</td>
</div>

<!-- This is the navigation bar for the homepage and the upload content page. -->
<div>
<ul class="w3-navbar w3-black">
<li><a href="/projects/upload">Moodslider Home</a></li>
<li><a href="/projects/create">Upload Content</a></li>
</ul>
</div>

<div class="w3-row-padding">
<div class="w3-panel">
<h1 style="text-align:center;color:black;font-size:50px;">Select a movie based on your mood</h1>
</div>

<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div class="col-md-12">

<div class="w3-row-padding">
<div class="w3-col m3 w3-center">
<label for="Agitated"><h3>Agitated</h3></label><br><br>
<label for="Happy"><h3>Happy</h3></label><br><br>
<label for="Tired"><h3>Tired</h3></label><br><br>
<label for="Scared"><h3>Scared</h3></label><br><br>
</div>

<div class="w3-col m6 w3-center">
<br>
<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div></div>
<input type="range" name="mood1" min="0" max="2" value="1" step="1";/><br><br>
<input type=submit value=Submit />

<br>
<br>
<input type="range" name="mood2" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood3" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood4" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
</div>
</form>
<div class="w3-col m3 w3-center">
<label for="Calm"><h3>Calm</h3></label><br><br>
<label for="Sad"><h3>Sad</h3></label><br><br>
<label for="WideAwake"><h3>Wide Awake</h3></label><br><br>
<label for="Fearless"><h3>Fearless</h3></label><br><br>
</div>
</div>

</form>

<!-- display the films images -->
<form action="/projects/upload">

<div class="w3-row">
<div type="text" name="lname" class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[1]->image?> ; alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[2]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[4]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[6]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[5]->image?> alt="" style="width:100%;max-width:150px"></div><br>

<!-- display the film name and description -->
<? $xml=simplexml_load_file("images/database.xml") or die("Error: Cannot create object");?>
<div class="w3-row"></div>
<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[1]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[2]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[4]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[6]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[5]->name?></h3></div>

<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[1]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[2]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[4]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[6]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[5]->description?></p></div>
</div>
</form>
<!--
<form action="/projects/upload" method="post" enctype="multipart/form-data">Select image to upload:
{{ @csrf_field() }}
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">
</form>
-->

</body>
</html>



ProjectsController (controller)




<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use OrchestraParserXmlFacade as XmlParser;

interface OutputType
{
public function generate();
}

//project class has been imported
use AppProject;

class ProjectsController extends Controller
{
public function index()
{
//because the class has been imported we can reference it like this rather than 'AppProject::all();'
$projects = Project::all();



//passing the JSON to the view

return view ('projects.index', ['projects'=> $projects]); //can also use 'compact('projects') instead of the ['projects'=> $projects]
}



//new method called create

public function create()
{

return view ('projects.create');

}

//new method called store


public function __construct()
{
$this->xml= new DOMDocument('1.0', 'ISO-8859-15');
}

public function createParent($type)
{
$this->parentElement = $this->xml->createElement($type);
return $this;
}

public function addElement($element, $type)
{
$this->elementGroup = $this->xml->createElement($type, $element);
return $this;
}

public function groupParentAndElements()
{
$this->parentElement->appendChild($this->elementGroup);
return $this;
}

public function generate()
{
$this->xml->appendChild($this->parentElement);
print $xml->saveXML('database.php'); //here I am saving and printing but you can change to suit your needs. It is at this point it is ready to generate the XML
}

public function store()
{

if (isset($_POST['submit'])) {
$xmlType = new XMLType();
$xmlType->createParent('programme')
->addElement('name', $_POST['name'])
->addElement('description', $_POST['description'])
->addElement('mood', $_POST['mood'])
->groupParentAndElements()
->createParent('others')
->addElement('example', 'Form submitted succesfully') //echos response
->groupParentAndElements();

//whenever you wish to output
$xmlType->generate('database.php');
}


return view('projects.upload');
}


//changed this from upload to show
public function upload()
{


return view('projects.upload');
}

//changed this from upload to show
public function show()
{


return view ('projects.upload', compact('user'));
}

public function slider()
{


return view ('projects.upload', compact('user'));
}


}



Database(XML)




<?xml version="1.0" encoding="UTF-8"?>
<programmeList>
<programme id="1">
<name>School of Rock</name>
<image>images/schoolofrock.jpg</image>
<description>After being kicked out of a rock band, Dewey Finn becomes a substitute teacher </description>
<mood>Agitated</mood>
</programme>
<programme id="2">
<name>Pitch Perfect 2</name>
<image>images/pitchperfect2.jpg</image>
<description>After a humiliating command performance at The Kennedy Center, the Barden Bellas enter an international competition that no American group has ever won in order to regain their status and right to perform. </description>
<mood>Fearless</mood>
</programme>
<programme id="3">
<name>Big</name>
<image>images/big.jpg</image>
<description>When a pre-teen boy wishes to be big at a magic wish machine, he wakes up the next morning and finds himself in an adult body.</description>
<mood>Tired</mood>
</programme>
</programmeList>









share|improve this question






















  • You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
    – user10341554
    Nov 23 '18 at 16:09
















0














I am building a web application that will show a variety of films on a site. As part of this project I have some range sliders that can be moved depending on the mood you are feeling. If someone is to move the slider and press submit, I am wanting a fresh new list of films to displayed.



This is where I am having issues, I am able to display a set amount of films on the page but can't figure out a way to refresh the films once I click the submit button after moving the sliders.



Code Below




Upload (view)




<link rel="stylesheet" href="CSS/app.css" type="text/css">
<meta name = "viewport" content="width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://www.w3schools.com. /lib/w3.css">
<!DOCTYPE html>
<html>
<head>
<title>Moodslider</title>
</head>
<body>

<!-- Sky logo + Sky cinema logo -->
<div class="box">
<td style="text-align:center;color:black;font-size:50px;">
<img src="/images/sky.png" title="Sky" alt="Sky" width="auto" height="125" />
</td>
<td style="text-align: right;position: relative; color:black;font-size:50px;">
<img src="/images/sky_cinema.png" title="sky_cinema" alt="Sky" width="auto" height="125" />
</td>
</div>

<!-- This is the navigation bar for the homepage and the upload content page. -->
<div>
<ul class="w3-navbar w3-black">
<li><a href="/projects/upload">Moodslider Home</a></li>
<li><a href="/projects/create">Upload Content</a></li>
</ul>
</div>

<div class="w3-row-padding">
<div class="w3-panel">
<h1 style="text-align:center;color:black;font-size:50px;">Select a movie based on your mood</h1>
</div>

<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div class="col-md-12">

<div class="w3-row-padding">
<div class="w3-col m3 w3-center">
<label for="Agitated"><h3>Agitated</h3></label><br><br>
<label for="Happy"><h3>Happy</h3></label><br><br>
<label for="Tired"><h3>Tired</h3></label><br><br>
<label for="Scared"><h3>Scared</h3></label><br><br>
</div>

<div class="w3-col m6 w3-center">
<br>
<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div></div>
<input type="range" name="mood1" min="0" max="2" value="1" step="1";/><br><br>
<input type=submit value=Submit />

<br>
<br>
<input type="range" name="mood2" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood3" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood4" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
</div>
</form>
<div class="w3-col m3 w3-center">
<label for="Calm"><h3>Calm</h3></label><br><br>
<label for="Sad"><h3>Sad</h3></label><br><br>
<label for="WideAwake"><h3>Wide Awake</h3></label><br><br>
<label for="Fearless"><h3>Fearless</h3></label><br><br>
</div>
</div>

</form>

<!-- display the films images -->
<form action="/projects/upload">

<div class="w3-row">
<div type="text" name="lname" class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[1]->image?> ; alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[2]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[4]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[6]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[5]->image?> alt="" style="width:100%;max-width:150px"></div><br>

<!-- display the film name and description -->
<? $xml=simplexml_load_file("images/database.xml") or die("Error: Cannot create object");?>
<div class="w3-row"></div>
<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[1]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[2]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[4]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[6]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[5]->name?></h3></div>

<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[1]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[2]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[4]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[6]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[5]->description?></p></div>
</div>
</form>
<!--
<form action="/projects/upload" method="post" enctype="multipart/form-data">Select image to upload:
{{ @csrf_field() }}
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">
</form>
-->

</body>
</html>



ProjectsController (controller)




<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use OrchestraParserXmlFacade as XmlParser;

interface OutputType
{
public function generate();
}

//project class has been imported
use AppProject;

class ProjectsController extends Controller
{
public function index()
{
//because the class has been imported we can reference it like this rather than 'AppProject::all();'
$projects = Project::all();



//passing the JSON to the view

return view ('projects.index', ['projects'=> $projects]); //can also use 'compact('projects') instead of the ['projects'=> $projects]
}



//new method called create

public function create()
{

return view ('projects.create');

}

//new method called store


public function __construct()
{
$this->xml= new DOMDocument('1.0', 'ISO-8859-15');
}

public function createParent($type)
{
$this->parentElement = $this->xml->createElement($type);
return $this;
}

public function addElement($element, $type)
{
$this->elementGroup = $this->xml->createElement($type, $element);
return $this;
}

public function groupParentAndElements()
{
$this->parentElement->appendChild($this->elementGroup);
return $this;
}

public function generate()
{
$this->xml->appendChild($this->parentElement);
print $xml->saveXML('database.php'); //here I am saving and printing but you can change to suit your needs. It is at this point it is ready to generate the XML
}

public function store()
{

if (isset($_POST['submit'])) {
$xmlType = new XMLType();
$xmlType->createParent('programme')
->addElement('name', $_POST['name'])
->addElement('description', $_POST['description'])
->addElement('mood', $_POST['mood'])
->groupParentAndElements()
->createParent('others')
->addElement('example', 'Form submitted succesfully') //echos response
->groupParentAndElements();

//whenever you wish to output
$xmlType->generate('database.php');
}


return view('projects.upload');
}


//changed this from upload to show
public function upload()
{


return view('projects.upload');
}

//changed this from upload to show
public function show()
{


return view ('projects.upload', compact('user'));
}

public function slider()
{


return view ('projects.upload', compact('user'));
}


}



Database(XML)




<?xml version="1.0" encoding="UTF-8"?>
<programmeList>
<programme id="1">
<name>School of Rock</name>
<image>images/schoolofrock.jpg</image>
<description>After being kicked out of a rock band, Dewey Finn becomes a substitute teacher </description>
<mood>Agitated</mood>
</programme>
<programme id="2">
<name>Pitch Perfect 2</name>
<image>images/pitchperfect2.jpg</image>
<description>After a humiliating command performance at The Kennedy Center, the Barden Bellas enter an international competition that no American group has ever won in order to regain their status and right to perform. </description>
<mood>Fearless</mood>
</programme>
<programme id="3">
<name>Big</name>
<image>images/big.jpg</image>
<description>When a pre-teen boy wishes to be big at a magic wish machine, he wakes up the next morning and finds himself in an adult body.</description>
<mood>Tired</mood>
</programme>
</programmeList>









share|improve this question






















  • You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
    – user10341554
    Nov 23 '18 at 16:09














0












0








0







I am building a web application that will show a variety of films on a site. As part of this project I have some range sliders that can be moved depending on the mood you are feeling. If someone is to move the slider and press submit, I am wanting a fresh new list of films to displayed.



This is where I am having issues, I am able to display a set amount of films on the page but can't figure out a way to refresh the films once I click the submit button after moving the sliders.



Code Below




Upload (view)




<link rel="stylesheet" href="CSS/app.css" type="text/css">
<meta name = "viewport" content="width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://www.w3schools.com. /lib/w3.css">
<!DOCTYPE html>
<html>
<head>
<title>Moodslider</title>
</head>
<body>

<!-- Sky logo + Sky cinema logo -->
<div class="box">
<td style="text-align:center;color:black;font-size:50px;">
<img src="/images/sky.png" title="Sky" alt="Sky" width="auto" height="125" />
</td>
<td style="text-align: right;position: relative; color:black;font-size:50px;">
<img src="/images/sky_cinema.png" title="sky_cinema" alt="Sky" width="auto" height="125" />
</td>
</div>

<!-- This is the navigation bar for the homepage and the upload content page. -->
<div>
<ul class="w3-navbar w3-black">
<li><a href="/projects/upload">Moodslider Home</a></li>
<li><a href="/projects/create">Upload Content</a></li>
</ul>
</div>

<div class="w3-row-padding">
<div class="w3-panel">
<h1 style="text-align:center;color:black;font-size:50px;">Select a movie based on your mood</h1>
</div>

<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div class="col-md-12">

<div class="w3-row-padding">
<div class="w3-col m3 w3-center">
<label for="Agitated"><h3>Agitated</h3></label><br><br>
<label for="Happy"><h3>Happy</h3></label><br><br>
<label for="Tired"><h3>Tired</h3></label><br><br>
<label for="Scared"><h3>Scared</h3></label><br><br>
</div>

<div class="w3-col m6 w3-center">
<br>
<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div></div>
<input type="range" name="mood1" min="0" max="2" value="1" step="1";/><br><br>
<input type=submit value=Submit />

<br>
<br>
<input type="range" name="mood2" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood3" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood4" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
</div>
</form>
<div class="w3-col m3 w3-center">
<label for="Calm"><h3>Calm</h3></label><br><br>
<label for="Sad"><h3>Sad</h3></label><br><br>
<label for="WideAwake"><h3>Wide Awake</h3></label><br><br>
<label for="Fearless"><h3>Fearless</h3></label><br><br>
</div>
</div>

</form>

<!-- display the films images -->
<form action="/projects/upload">

<div class="w3-row">
<div type="text" name="lname" class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[1]->image?> ; alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[2]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[4]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[6]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[5]->image?> alt="" style="width:100%;max-width:150px"></div><br>

<!-- display the film name and description -->
<? $xml=simplexml_load_file("images/database.xml") or die("Error: Cannot create object");?>
<div class="w3-row"></div>
<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[1]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[2]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[4]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[6]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[5]->name?></h3></div>

<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[1]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[2]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[4]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[6]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[5]->description?></p></div>
</div>
</form>
<!--
<form action="/projects/upload" method="post" enctype="multipart/form-data">Select image to upload:
{{ @csrf_field() }}
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">
</form>
-->

</body>
</html>



ProjectsController (controller)




<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use OrchestraParserXmlFacade as XmlParser;

interface OutputType
{
public function generate();
}

//project class has been imported
use AppProject;

class ProjectsController extends Controller
{
public function index()
{
//because the class has been imported we can reference it like this rather than 'AppProject::all();'
$projects = Project::all();



//passing the JSON to the view

return view ('projects.index', ['projects'=> $projects]); //can also use 'compact('projects') instead of the ['projects'=> $projects]
}



//new method called create

public function create()
{

return view ('projects.create');

}

//new method called store


public function __construct()
{
$this->xml= new DOMDocument('1.0', 'ISO-8859-15');
}

public function createParent($type)
{
$this->parentElement = $this->xml->createElement($type);
return $this;
}

public function addElement($element, $type)
{
$this->elementGroup = $this->xml->createElement($type, $element);
return $this;
}

public function groupParentAndElements()
{
$this->parentElement->appendChild($this->elementGroup);
return $this;
}

public function generate()
{
$this->xml->appendChild($this->parentElement);
print $xml->saveXML('database.php'); //here I am saving and printing but you can change to suit your needs. It is at this point it is ready to generate the XML
}

public function store()
{

if (isset($_POST['submit'])) {
$xmlType = new XMLType();
$xmlType->createParent('programme')
->addElement('name', $_POST['name'])
->addElement('description', $_POST['description'])
->addElement('mood', $_POST['mood'])
->groupParentAndElements()
->createParent('others')
->addElement('example', 'Form submitted succesfully') //echos response
->groupParentAndElements();

//whenever you wish to output
$xmlType->generate('database.php');
}


return view('projects.upload');
}


//changed this from upload to show
public function upload()
{


return view('projects.upload');
}

//changed this from upload to show
public function show()
{


return view ('projects.upload', compact('user'));
}

public function slider()
{


return view ('projects.upload', compact('user'));
}


}



Database(XML)




<?xml version="1.0" encoding="UTF-8"?>
<programmeList>
<programme id="1">
<name>School of Rock</name>
<image>images/schoolofrock.jpg</image>
<description>After being kicked out of a rock band, Dewey Finn becomes a substitute teacher </description>
<mood>Agitated</mood>
</programme>
<programme id="2">
<name>Pitch Perfect 2</name>
<image>images/pitchperfect2.jpg</image>
<description>After a humiliating command performance at The Kennedy Center, the Barden Bellas enter an international competition that no American group has ever won in order to regain their status and right to perform. </description>
<mood>Fearless</mood>
</programme>
<programme id="3">
<name>Big</name>
<image>images/big.jpg</image>
<description>When a pre-teen boy wishes to be big at a magic wish machine, he wakes up the next morning and finds himself in an adult body.</description>
<mood>Tired</mood>
</programme>
</programmeList>









share|improve this question













I am building a web application that will show a variety of films on a site. As part of this project I have some range sliders that can be moved depending on the mood you are feeling. If someone is to move the slider and press submit, I am wanting a fresh new list of films to displayed.



This is where I am having issues, I am able to display a set amount of films on the page but can't figure out a way to refresh the films once I click the submit button after moving the sliders.



Code Below




Upload (view)




<link rel="stylesheet" href="CSS/app.css" type="text/css">
<meta name = "viewport" content="width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://www.w3schools.com. /lib/w3.css">
<!DOCTYPE html>
<html>
<head>
<title>Moodslider</title>
</head>
<body>

<!-- Sky logo + Sky cinema logo -->
<div class="box">
<td style="text-align:center;color:black;font-size:50px;">
<img src="/images/sky.png" title="Sky" alt="Sky" width="auto" height="125" />
</td>
<td style="text-align: right;position: relative; color:black;font-size:50px;">
<img src="/images/sky_cinema.png" title="sky_cinema" alt="Sky" width="auto" height="125" />
</td>
</div>

<!-- This is the navigation bar for the homepage and the upload content page. -->
<div>
<ul class="w3-navbar w3-black">
<li><a href="/projects/upload">Moodslider Home</a></li>
<li><a href="/projects/create">Upload Content</a></li>
</ul>
</div>

<div class="w3-row-padding">
<div class="w3-panel">
<h1 style="text-align:center;color:black;font-size:50px;">Select a movie based on your mood</h1>
</div>

<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div class="col-md-12">

<div class="w3-row-padding">
<div class="w3-col m3 w3-center">
<label for="Agitated"><h3>Agitated</h3></label><br><br>
<label for="Happy"><h3>Happy</h3></label><br><br>
<label for="Tired"><h3>Tired</h3></label><br><br>
<label for="Scared"><h3>Scared</h3></label><br><br>
</div>

<div class="w3-col m6 w3-center">
<br>
<form action="/projects/upload" method="post" enctype="multipart/form-data">
{{ @csrf_field() }}
<div></div>
<input type="range" name="mood1" min="0" max="2" value="1" step="1";/><br><br>
<input type=submit value=Submit />

<br>
<br>
<input type="range" name="mood2" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood3" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
<input type="range" name="mood4" min="0" max="2" value="1" step="1" class="slider" id="myRange"><br><br>
<input type="submit" value="Submit">
<br>
<br>
</div>
</form>
<div class="w3-col m3 w3-center">
<label for="Calm"><h3>Calm</h3></label><br><br>
<label for="Sad"><h3>Sad</h3></label><br><br>
<label for="WideAwake"><h3>Wide Awake</h3></label><br><br>
<label for="Fearless"><h3>Fearless</h3></label><br><br>
</div>
</div>

</form>

<!-- display the films images -->
<form action="/projects/upload">

<div class="w3-row">
<div type="text" name="lname" class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[1]->image?> ; alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[2]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[4]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[6]->image?> alt="" style="width:100%;max-width:150px"></div>
<div class="w3-col w3-container" style="width:20%"><img src=<?$xml=simplexml_load_file("images/database.xml");
echo '../'.$xml->programme[5]->image?> alt="" style="width:100%;max-width:150px"></div><br>

<!-- display the film name and description -->
<? $xml=simplexml_load_file("images/database.xml") or die("Error: Cannot create object");?>
<div class="w3-row"></div>
<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[1]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[2]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[4]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[6]->name?></h3></div>
<div class="w3-col w3-container" style="width:20%"><h3><?echo $xml->programme[5]->name?></h3></div>

<div class="w3-row">
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[1]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[2]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[4]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[6]->description?></p></div>
<div class="w3-col w3-container" style="width:20%"><p><?echo $xml->programme[5]->description?></p></div>
</div>
</form>
<!--
<form action="/projects/upload" method="post" enctype="multipart/form-data">Select image to upload:
{{ @csrf_field() }}
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">
</form>
-->

</body>
</html>



ProjectsController (controller)




<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use OrchestraParserXmlFacade as XmlParser;

interface OutputType
{
public function generate();
}

//project class has been imported
use AppProject;

class ProjectsController extends Controller
{
public function index()
{
//because the class has been imported we can reference it like this rather than 'AppProject::all();'
$projects = Project::all();



//passing the JSON to the view

return view ('projects.index', ['projects'=> $projects]); //can also use 'compact('projects') instead of the ['projects'=> $projects]
}



//new method called create

public function create()
{

return view ('projects.create');

}

//new method called store


public function __construct()
{
$this->xml= new DOMDocument('1.0', 'ISO-8859-15');
}

public function createParent($type)
{
$this->parentElement = $this->xml->createElement($type);
return $this;
}

public function addElement($element, $type)
{
$this->elementGroup = $this->xml->createElement($type, $element);
return $this;
}

public function groupParentAndElements()
{
$this->parentElement->appendChild($this->elementGroup);
return $this;
}

public function generate()
{
$this->xml->appendChild($this->parentElement);
print $xml->saveXML('database.php'); //here I am saving and printing but you can change to suit your needs. It is at this point it is ready to generate the XML
}

public function store()
{

if (isset($_POST['submit'])) {
$xmlType = new XMLType();
$xmlType->createParent('programme')
->addElement('name', $_POST['name'])
->addElement('description', $_POST['description'])
->addElement('mood', $_POST['mood'])
->groupParentAndElements()
->createParent('others')
->addElement('example', 'Form submitted succesfully') //echos response
->groupParentAndElements();

//whenever you wish to output
$xmlType->generate('database.php');
}


return view('projects.upload');
}


//changed this from upload to show
public function upload()
{


return view('projects.upload');
}

//changed this from upload to show
public function show()
{


return view ('projects.upload', compact('user'));
}

public function slider()
{


return view ('projects.upload', compact('user'));
}


}



Database(XML)




<?xml version="1.0" encoding="UTF-8"?>
<programmeList>
<programme id="1">
<name>School of Rock</name>
<image>images/schoolofrock.jpg</image>
<description>After being kicked out of a rock band, Dewey Finn becomes a substitute teacher </description>
<mood>Agitated</mood>
</programme>
<programme id="2">
<name>Pitch Perfect 2</name>
<image>images/pitchperfect2.jpg</image>
<description>After a humiliating command performance at The Kennedy Center, the Barden Bellas enter an international competition that no American group has ever won in order to regain their status and right to perform. </description>
<mood>Fearless</mood>
</programme>
<programme id="3">
<name>Big</name>
<image>images/big.jpg</image>
<description>When a pre-teen boy wishes to be big at a magic wish machine, he wakes up the next morning and finds himself in an adult body.</description>
<mood>Tired</mood>
</programme>
</programmeList>






php xml laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 13:31









Matthew

116




116












  • You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
    – user10341554
    Nov 23 '18 at 16:09


















  • You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
    – user10341554
    Nov 23 '18 at 16:09
















You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
– user10341554
Nov 23 '18 at 16:09




You should try to dynamically display your data - this will take up less lines of code and be more future-proof (i.e. if you add more programmes to your programme list). You can do this by decoding the json array and using a foreach loop foreach($programmes as $programme) etc....
– user10341554
Nov 23 '18 at 16:09












1 Answer
1






active

oldest

votes


















0














You need to POST the request data (from the form which the user submits) and display the films based on that. You will need some logic to determine which mood in the database you are searching for, and set that to the variable $mood which you will search for in your projects table.



In your controller:



public function index(Request $request)
{

// Need logic that checks if there is anything in the request
// If there is nothing in the request, then show all films

// Repeat this for every input slider you have
$mood1 = $request->input('mood1'); // This will return the value of the slider

// You will need some logic which will calculate which mood to search
// your database for, i.e. if $mood1 < 3 && $mood2 > 1 etc.
$mood = /** LOGIC FOR YOUR MOOD **/ ;

$projects = Project::where('mood', $mood);

return view ('projects.index', ['projects'=> $projects]);
}


In your form you will need



<form action="/projects/upload" method="POST">
// And importantly, you will need to protect against CSRF when POSTing
{{ csrf_field() }}


And you will also need to create a 'POST' route.



Hope this helped!






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447649%2fnew-films-will-refresh-when-the-submit-button-is-pressed-after-the-range-slider%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to POST the request data (from the form which the user submits) and display the films based on that. You will need some logic to determine which mood in the database you are searching for, and set that to the variable $mood which you will search for in your projects table.



    In your controller:



    public function index(Request $request)
    {

    // Need logic that checks if there is anything in the request
    // If there is nothing in the request, then show all films

    // Repeat this for every input slider you have
    $mood1 = $request->input('mood1'); // This will return the value of the slider

    // You will need some logic which will calculate which mood to search
    // your database for, i.e. if $mood1 < 3 && $mood2 > 1 etc.
    $mood = /** LOGIC FOR YOUR MOOD **/ ;

    $projects = Project::where('mood', $mood);

    return view ('projects.index', ['projects'=> $projects]);
    }


    In your form you will need



    <form action="/projects/upload" method="POST">
    // And importantly, you will need to protect against CSRF when POSTing
    {{ csrf_field() }}


    And you will also need to create a 'POST' route.



    Hope this helped!






    share|improve this answer


























      0














      You need to POST the request data (from the form which the user submits) and display the films based on that. You will need some logic to determine which mood in the database you are searching for, and set that to the variable $mood which you will search for in your projects table.



      In your controller:



      public function index(Request $request)
      {

      // Need logic that checks if there is anything in the request
      // If there is nothing in the request, then show all films

      // Repeat this for every input slider you have
      $mood1 = $request->input('mood1'); // This will return the value of the slider

      // You will need some logic which will calculate which mood to search
      // your database for, i.e. if $mood1 < 3 && $mood2 > 1 etc.
      $mood = /** LOGIC FOR YOUR MOOD **/ ;

      $projects = Project::where('mood', $mood);

      return view ('projects.index', ['projects'=> $projects]);
      }


      In your form you will need



      <form action="/projects/upload" method="POST">
      // And importantly, you will need to protect against CSRF when POSTing
      {{ csrf_field() }}


      And you will also need to create a 'POST' route.



      Hope this helped!






      share|improve this answer
























        0












        0








        0






        You need to POST the request data (from the form which the user submits) and display the films based on that. You will need some logic to determine which mood in the database you are searching for, and set that to the variable $mood which you will search for in your projects table.



        In your controller:



        public function index(Request $request)
        {

        // Need logic that checks if there is anything in the request
        // If there is nothing in the request, then show all films

        // Repeat this for every input slider you have
        $mood1 = $request->input('mood1'); // This will return the value of the slider

        // You will need some logic which will calculate which mood to search
        // your database for, i.e. if $mood1 < 3 && $mood2 > 1 etc.
        $mood = /** LOGIC FOR YOUR MOOD **/ ;

        $projects = Project::where('mood', $mood);

        return view ('projects.index', ['projects'=> $projects]);
        }


        In your form you will need



        <form action="/projects/upload" method="POST">
        // And importantly, you will need to protect against CSRF when POSTing
        {{ csrf_field() }}


        And you will also need to create a 'POST' route.



        Hope this helped!






        share|improve this answer












        You need to POST the request data (from the form which the user submits) and display the films based on that. You will need some logic to determine which mood in the database you are searching for, and set that to the variable $mood which you will search for in your projects table.



        In your controller:



        public function index(Request $request)
        {

        // Need logic that checks if there is anything in the request
        // If there is nothing in the request, then show all films

        // Repeat this for every input slider you have
        $mood1 = $request->input('mood1'); // This will return the value of the slider

        // You will need some logic which will calculate which mood to search
        // your database for, i.e. if $mood1 < 3 && $mood2 > 1 etc.
        $mood = /** LOGIC FOR YOUR MOOD **/ ;

        $projects = Project::where('mood', $mood);

        return view ('projects.index', ['projects'=> $projects]);
        }


        In your form you will need



        <form action="/projects/upload" method="POST">
        // And importantly, you will need to protect against CSRF when POSTing
        {{ csrf_field() }}


        And you will also need to create a 'POST' route.



        Hope this helped!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 16:07









        user10341554

        1028




        1028






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447649%2fnew-films-will-refresh-when-the-submit-button-is-pressed-after-the-range-slider%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista