Hidden Input Values not being passed through form

2019-09-08 20:07发布

I have a small html file working in the frame of a website. It currently requests a zip code and then calls a php page to query the database. The iframe gets the id number from the parent page and then gets the zip code from its own page. Here is the code snippet.

<script>
pid = window.location.search;
pid = pid.substring(11,16)
htmlout = '<input type = "hidden" name = "productid" id = "productid" value = "' + pid + '">';
</script>
<body style="margin: 0px; background-color: #ECECEC;">

<form action="https://www.net10wirelessphones.com/Mini-zip-Lookup.html" style="text-align: left" method = "get">
<script>
document.write(htmlout);
</script><span style="font-size: 9pt"><span style="font-family: Arial, Helvetica, sans-serif; color: #444444">Verify coverage in your area. Enter your Zip Code: 
</span>&nbsp;     
</span>
<input name="zip" size="5" type="text" />
<input type="submit" value="GO" />&nbsp;</form>

However, When I enter the zip code 00631, it only goes to the site http://www.net10wirelessphones.com/Mini-zip-Lookup.html?zip=00631

It seems to be cutting off the hidden value from the form. Any suggestions on what I may be doing wrong?

Edit: For those of you wanting to try it out, try it with the zip code 00631 and the product id 17637. It should accept this option and direct to the zipsuccess page.

Edit: Also, if you want to see it from the start go to the page https://www.net10wirelessphones.com/zipstart.html?productid=17637. Sorry I forgot to include it for those who have been trying it out.

标签: php html forms
4条回答
甜甜的少女心
2楼-- · 2019-09-08 20:38

I had a very similar problem and changing the names as stated above fixed it...to a point. I thought it might be useful to include what was actually the issue. I had my variables being set backwards. I was resetting the $_POST variable with a blank value every time. I was trying to add the $_POST values to an array and had it thus:

$_POST['varname'] = $my_array['varname'];

Once I changed it to:

$my_array['varname'] = $_POST['varname'];

It worked perfectly. Hopefully my time spend staring at this silly mistake will save someone else from doing the same.

查看更多
在下西门庆
3楼-- · 2019-09-08 20:53

I got the program to work. It turns out the problem was in another form that sent to this page. I had to make a slight change to a name attribute..

This:

<input name="id" id="productid" type="hidden" value="" />

Changed to:

 <input name="productid" type="hidden" id="productid" value="" />

And it worked fine. Thanks guys for your help!

查看更多
贪生不怕死
4楼-- · 2019-09-08 20:54

I manually supplied productid as a GET parameter to your zipfail.html page. It's putting the value into the hidden input field just fine. It's also passing it to Mini-zip-lookup.html without flaw. It appears that either:

  1. You're not be providing the productid in the frame's url.
  2. Or the relevant code on that page is different from zipfail.html

Make sure the iframe's url has ?productid=?<number> on the end.

查看更多
smile是对你的礼貌
5楼-- · 2019-09-08 20:58

You don't need to do that. Here is a better alternative

<script>
pid = window.location.search;
pid = pid.substring(11,16)

//here is the changes
document.getElementById("productid").value = pid;
</script>

<form action="https://www.net10wirelessphones.com/Mini-zip-Lookup.html" style="text-align: left" method = "get">
<input type = "hidden" name = "productid" id = "productid" value = "" />

<span style="font-size: 9pt"><span style="font-family: Arial, Helvetica, sans-serif; color: #444444">Verify coverage in your area. Enter your Zip Code: 
</span>&nbsp;     
</span>
<input name="zip" size="5" type="text" />
<input type="submit" value="GO" />&nbsp;</form>
查看更多
登录 后发表回答