Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi,

 

I have a script that works OK but I'm not sure if it's by design or by accident.

 

On pages 91 through 94, Larry advises on how to use PHP redux, a technique that I use often.

 

Here's my scenario:

 

I have a PHP script, let's call it script one, that calls PHP script 2 and passes a key value to it.  I test for a key value as the first thing in script 2 via 'if (isset($GET['key']))' and retrieve its value. This works fine.

 

Then script 2 uses that key value to populate a form with values from a database select. The user is able to change any of the values in the form. Script 2 then calls itself via PHP redux.

 

Now this is the part that I don't quite understand.  The form is method=POST and that same key value is included in the form via an input type=hidden, a name of 'key', and the value via a PHP echo.

 

But the test for isset($GET['key']) still works and retrieves the correct value for key.  But the form is POST?  On the URL for the redux-called script two I can see the '?key=key-value suffix.

 

Can someone please help me understand this?

 

Thank you in anticipation.

Share this post


Link to post
Share on other sites

The action attribute value of your HTML form is the URL that the form will post to.

As such, if there is a ?name=value part on the end of the URL set for the action attribute, then you will be able to access that name-value pair via the GET method when you post the form.

If you don't want this, the simple solution is to not put the ?name=value part on the end of the URL specified for the action attribute of the form.

Share this post


Link to post
Share on other sites

Hi HartleySan,

 

I do not have an action value at all in my form.  Some time ago Larry advised to not use that when doing a redux - apparently it defaults to the current script URL and maybe that is why the GET/key is still there from the first call?

 

Thanks again for your interest and advice.

 

Cheers from Oz.

Share this post


Link to post
Share on other sites

It's very possible, but I don't know off the top of my head.

I usually hesitate from doing things like leaving attribute values blank, because the default behavior can differ from browser to browser.

I would recommend specifying an actual value, be it with or with out URL parameters.

Share this post


Link to post
Share on other sites

Necuima, your understanding is exactly correct. Because it has no action attribute, the current URL is used, and that URL has the GET parameter attached.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...