Jump to content

PHP $_GET issue


lightlydone

Recommended Posts

Hi,

 

I'm using $_GET to pass form data to a URL -

 

http://localhost/projects/phpget/test.php?Q7=Dave&Q8=Smith&Q9=123+Road&Q10=ls11sl&Q2=dave%40hotmail.com&Q4=71&day=19&month=01&year=1995&Q263=3127&Q262=3126&x=99&y=24

 

All the form fields are named Qx and all are ok apart from dob.

 

I've been trying to get the dob to be passed as dd-mm-yyyy with name of Q5, so in above example would be:

 

http://localhost/projects/phpget/test.php?Q7=Dave&Q8=Smith&Q9=123+Road&Q10=ls11sl&Q2=dave%40hotmail.com&Q4=71&Q5=19-01-1995&Q263=3127&Q262=3126&x=99&y=24

 

I cannot name all 3 fields (date, month, year) as Q5 si i'm guessing that the 3 values need to be assinged to Q5 before the form is submitted??

 

Any help on this would be much appreciated as hours of trawling through google has not helped.

 

Many thanks.

Link to comment
Share on other sites

There are two ways.

 

1: On submit button click, use JS to create a hidden input (Q5) in the form and assign its value, then disable the day, month, and year fields so they are not submitted.

2: Have the form POST to the same page, use PHP to generate the query string and then header redirect to the correct URL with the query string appended.

Link to comment
Share on other sites

Thanks for your reply.

 

I will have to use the JS solution as I am already using header redirect to redirect to a thankyou page after the form has been submitted.

 

I know absolutley no JS and cannot make sense of how to implement the JS solution (after 5 days of trying!!).

 

Could anyone tell me how to do this?

 

Thanks.

Link to comment
Share on other sites

Im trying to pass form data into URL using $_GET, which i understand.

 

The prob is that the dob fields are named <select name="day" id="select" style="width:70px;">, <select name="month" id="select2" style="width:70px;"> and  <select name="year" id="select3" style="width:80px;"> so in the URL i get ?day=29&month=01&year=1927 when I need it to be ?dob=29-01-1927.

 

So i guess i need to somehow OnSubmit get the 3 values and put them into 1 value=dob, then disable the day, month and year values so they don't appear in the URL as well.

 

Does this make sense?

Link to comment
Share on other sites

I know you didn't say this is being inserted in a DB, so I'm making kind of an assumption here, but is there a reason you can't just concatenate the three in the script that does the processing, either before or within the DB query?

 

$dob = "{$_POST['year']}-{$_POST['month']}-{$_POST['day']}";

 

then use $dob in the insert, or concatenate the values directly in the query

 

INSERT INTO `table` (dob) VALUES ( CONCAT_WS( '-', $_POST['year'], $_POST['month'], $_POST['day']) )

Link to comment
Share on other sites

Im not inserting the data into a DB.

 

Im sending the data to a URL:

 

https://www.xxx.co.uk/xxx/en/members/livefeed.aspx?ref=vc_an_lf&q2=bob@bobmail.com&Q4=71&Q5=07-05-1980&Q7=Bob&Q8=Smith&Q9=1+Sesame+Street+London&Q10=sw123sh&Q262=3126&Q263=3127

 

All the fields are named q2=email, Q7=forename etc... and all work as above.

 

I have to name the dob drop down fields as day, month, year so 3 names. i need to put all 3 of these values under 1 name, Q5, so the query string includes Q5=07-05-1990

Link to comment
Share on other sites

Hmmm... The only thing that comes to mind at the moment is to use a different date picker, one that can be configured as to how the value should be formatted and sent, and what variable's name should be. I've used this one from DynamicDrive in the past. It's highly configurable, and pretty easy to implement.

Link to comment
Share on other sites

yeah i think javascript is the way to go.

 

Simshaun suggested: "On submit button click, use JS to create a hidden input (Q5) in the form and assign its value, then disable the day, month, and year fields so they are not submitted."

 

But, alas, my js is very poor.

 

Does anyone no how to do this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.