0

I have a simple form which allows the User to enter from_date and to_date.Lets say a user enters 2014年09月01日 and 2014年09月10日 respectively.

How can I get this form submit to a URL ../from_date/2014-09-01/to_date/2014-09-10

Marcin Nabiałek
112k43 gold badges271 silver badges299 bronze badges
asked Sep 22, 2014 at 6:05

2 Answers 2

1

You cannot do that but if you need to do something like this, you need to submit to standard class Controller and then resubmit it using redirection:

public function resubmit() {
 Redirect::to('/from_date/'.Input::get('from_date').'/to_date/'.Input::get('to_date'))->withInput();
}

But to be honest I don't know why you try to do that. Usually you post data to static url and display content using dynamic urls with pretty urls.

answered Sep 22, 2014 at 6:36
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Marcin for your response. The reason I want to submit the user input like this I want to take advantage of the pretty url. I create a route : ../from_date/{from_date}/to_date/{to_date} which will pull all the posts posted between from and to dates. What do you suggest is the best way to achieve this functionality.
Does that mean that Pretty Urls can only work if we were to use them as a link. How can we use a User Input as a parameter to the pretty URL. Thanks much for your help.
@ComradeRaj You can make redirection to pretty url as I showed you above
0

To change the URL once the page has already loaded, you will need to use javascript, as you won't be able to do this using Laravel/PHP because you need access to the dates, which are only selected after the page has loaded.

If your form is similar to:

<form id="dateForm" onsubmit="return submitDateForm()">
 <input type="text" id="from_date" name="from_date">
 <input type="text" id="to_date" name="to_date">
</form>

Assuming you are using POST for the form submission, and have already imported jQuery, then insert into your view (or a separate .js file which you import) the following jQuery:

function submitDateForm() {
 var from_date = $( '#from_date' ).val();
 var to_date = $( '#to_date' ).val();
 //Send the request
 var request = $.post("../from_date/" + from_date + "/to_date/" + to_date);
 //prevent the form from submitting itself normally
 return false;
}
answered Sep 22, 2014 at 14:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.