1

I have the form up, but when I type something in and submit it it just refreshes the page. I'm not entirely sure how to use render and redirect so it's a bit of guess work, but no luck.

The controller is quote.php, the form is quote_form.php, and the template for displaying the quote is quote_template.php. My code is below:

quote.php

quote_form.php

quote_template.php

I've struggled a lot with the material for this problem set. Watched the lectures twice and watched the walkthroughs and sections several times. Any help would be much appreciated.

1 Answer 1

3

You definitely don't need to do this:

redirect("/../views/quote_template.php");

... after you have used the render() function.

EDIT:

For quote.php, you should be doing something like this (in pseudo-code):

<?php

    // configuration

    // if user reached page via GET (as by clicking a link or via redirect)

        // else render form

    // else if user reached page via POST (as by submitting a form via POST)

        // validate submission
        // if symbol not in $_POST, apologize

        // Look up that stock

        // if symbol not found, apologize

        // else render quote
?>

You should look at the distribution code provided by CS50 Staff in the pset7.zip archive, and pay special attention to the parts that have comments like those in my pseudo-code above, especially the sections relating to // configuration, // if user reached page via GET, and // if user reached page via POST.

EDIT2:

Here's your problem: You need to use <form action="quote.php" method="post"> in your quote_form.php View. You can't use method="get", and here is why. When the quote.php Controller is reached via GET, it will render the quote_form.php View. That's why your code appears to just be refreshing the page. You want it to render the quote_template.php View instead, but only if it is responding to a form submission.

If this answers your question, be sure to click on the green checkmark to accept it. Or post an answer of your own and accept that -- I don't care, as long as you mark the question as answered to prevent it from becoming a zombie question!

4
  • Ok thanks. I didn't have that originally and added it because my page wouldn't redirect. I can remove it but the code still doesn't work.
    – DSmith
    Commented Aug 27, 2016 at 22:51
  • 1
    I don't condition on GET or POST because my form only submits vie get, so it seems unnecessary. As far as I know I do follow that pseudo code though.
    – DSmith
    Commented Aug 28, 2016 at 0:18
  • Well, there's your problem. See explanation above. Commented Aug 28, 2016 at 1:21
  • 1
    Thanks, I see what's wrong now.
    – DSmith
    Commented Aug 28, 2016 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .