Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Quick PHP/HTML Forms question.
New Posts  All Forums:Forum Nav:

Quick PHP/HTML Forms question.

post #1 of 8
Thread Starter 
Alright. So I'm writing a simple gallery script for my dad's website.

For this gallery, I have a separate form for adding images to a specific album. I'd like to have a SELECT that will allow the user to choose how many images will be added to the album. Choosing to add 3 images would "refresh" the form to have 3 upload boxes.

How do I go about writing this? Is it as simple as this:

...
print<<<end
<select name="numImages">
<option value = 1>1</option>
<option value = 2>2</option>
<option value = 3>3</option>
<option value = 4>4</option>
<option value = 5>5</option>
</select>
<br>
end;

$i=0;
while($i < $numImages)
{
print "<input name=\\"images[]\\" type=\\"fill\\">";
print "<br>";
}
...


Something tells me that's not it.

Thanks.
Jillian
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K MSI P67A-G45 B3 MSI GeForce GTX560 Ti GSKILL F3-10666CL9D-8GBRL 
CoolingOSKeyboardPower
Cooler Master Hyper 212 Plus Windows 7 Professional 64-bit Razer Lycosa Corsair 520HX 
CaseMouse
Cooler Master Stacker 830 Razer Mamba 
  hide details  
Reply
Jillian
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K MSI P67A-G45 B3 MSI GeForce GTX560 Ti GSKILL F3-10666CL9D-8GBRL 
CoolingOSKeyboardPower
Cooler Master Hyper 212 Plus Windows 7 Professional 64-bit Razer Lycosa Corsair 520HX 
CaseMouse
Cooler Master Stacker 830 Razer Mamba 
  hide details  
Reply
post #2 of 8
You need JavaScript to do that code because PHP is all server-side code and won't work to dynamically change anything on the client side. I don't know enough Javascript to help you out with it, though.
Macbook
(17 items)
 
  
CPUGraphicsRAMHard Drive
Intel P8600 @ 2.4Ghz Geforce 9400M 6GB Crucial DDR3-1066 OCZ Vertex 2 128GB 
Hard DriveOptical DriveOSOS
External 1TB Broken and Making Funny Noises OS X Lion Windows 8 Preview 
MonitorMonitorKeyboardPower
13.3" 1280x800 Dell 2407WFP-HC Backlit Lithium-Polymer Battery 
CaseMouseAudio
Unibody Multi-Touch Trackpad JVC Marshmallow's 
  hide details  
Reply
Macbook
(17 items)
 
  
CPUGraphicsRAMHard Drive
Intel P8600 @ 2.4Ghz Geforce 9400M 6GB Crucial DDR3-1066 OCZ Vertex 2 128GB 
Hard DriveOptical DriveOSOS
External 1TB Broken and Making Funny Noises OS X Lion Windows 8 Preview 
MonitorMonitorKeyboardPower
13.3" 1280x800 Dell 2407WFP-HC Backlit Lithium-Polymer Battery 
CaseMouseAudio
Unibody Multi-Touch Trackpad JVC Marshmallow's 
  hide details  
Reply
post #3 of 8
Quote:
Originally Posted by Fkyx View Post
Alright. So I'm writing a simple gallery script for my dad's website.

For this gallery, I have a separate form for adding images to a specific album. I'd like to have a SELECT that will allow the user to choose how many images will be added to the album. Choosing to add 3 images would "refresh" the form to have 3 upload boxes.

How do I go about writing this? Is it as simple as this:

...
print<<<end
<select name="numImages">
<option value = 1>1</option>
<option value = 2>2</option>
<option value = 3>3</option>
<option value = 4>4</option>
<option value = 5>5</option>
</select>
<br>
end;

$i=0;
while($i < $numImages)
{
print "<input name=\\"images[]\\" type=\\"fill\\">";
print "<br>";
}
...


Something tells me that's not it.

Thanks.
It will work if you make to forms.
First is the select input. And set attribute on the select onchange="this.form.submit();"
The other form will be generated dynamically by the PHP.
i.e. $numImages = $_POST['from_the_first_form'].
And afther that you have to put make an iteration of the $_FILES superglobal array, in order to work with the uploaded files.

But with Javascript will be better.. the only problem is that wit will be more complex/difficult to be done.
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
post #4 of 8
look into AJAX and XMLHttpRequest
Legendary Awesome
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E4600 2.88GHz OC'd 20% through BIOS ASUS Striker Extreme XFX GeForce 9800 GTX(G92) 512MB G.Skill DDR2 800 4GB 
Hard DriveOptical DriveOSMonitor
150 Raptor, 250, 250, (RIP) 1000 DVD/RW Vista Home Premium x64 19" Samsung monitor, 24" Dell Monitor 
KeyboardPowerCaseMouse
Logitech G15 600W Antec Twelve Hundred Logitech MX518 
  hide details  
Reply
Legendary Awesome
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E4600 2.88GHz OC'd 20% through BIOS ASUS Striker Extreme XFX GeForce 9800 GTX(G92) 512MB G.Skill DDR2 800 4GB 
Hard DriveOptical DriveOSMonitor
150 Raptor, 250, 250, (RIP) 1000 DVD/RW Vista Home Premium x64 19" Samsung monitor, 24" Dell Monitor 
KeyboardPowerCaseMouse
Logitech G15 600W Antec Twelve Hundred Logitech MX518 
  hide details  
Reply
post #5 of 8
Quote:
Originally Posted by mentholmoose View Post
You need JavaScript to do that code because PHP is all server-side code and won't work to dynamically change anything on the client side. I don't know enough Javascript to help you out with it, though.
ajax
post #6 of 8
Quote:
Originally Posted by LyokoHaCk View Post
ajax
You people, are AJAX obsessed, aren't you?

I would use AJAX only in case of not knowing how to program in JavaScript.
I was thinking of a simple solution:
Code:
<script>
function generateUploadInputs(num){
 inputCont = document.getElementById('uploadInputs');
 inputCont.innerHTML = '';
 for (var i =0; i < num; i++) inputCont.innerHTML += '<input type="file" name="images[]" />n<br />';
}
</script>
<select name="numImages" onchange="generateUploadInputs(this.options[this.selectedIndex]);">
<option value = 1>1</option>
<option value = 2>2</option>
<option value = 3>3</option>
<option value = 4>4</option>
<option value = 5>5</option>
</select>

<div id="uploadInputs">

</div>

Edited by metala - 7/18/08 at 6:19am
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
post #7 of 8
You shouldn't rely on innerHTML. That standard has been deprecated.

Look into using the DOM (Document Object Model). With that, you create elements on the fly and it has better compatibility with most browsers. It's also easier to use with XML requests.
Legendary Awesome
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E4600 2.88GHz OC'd 20% through BIOS ASUS Striker Extreme XFX GeForce 9800 GTX(G92) 512MB G.Skill DDR2 800 4GB 
Hard DriveOptical DriveOSMonitor
150 Raptor, 250, 250, (RIP) 1000 DVD/RW Vista Home Premium x64 19" Samsung monitor, 24" Dell Monitor 
KeyboardPowerCaseMouse
Logitech G15 600W Antec Twelve Hundred Logitech MX518 
  hide details  
Reply
Legendary Awesome
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E4600 2.88GHz OC'd 20% through BIOS ASUS Striker Extreme XFX GeForce 9800 GTX(G92) 512MB G.Skill DDR2 800 4GB 
Hard DriveOptical DriveOSMonitor
150 Raptor, 250, 250, (RIP) 1000 DVD/RW Vista Home Premium x64 19" Samsung monitor, 24" Dell Monitor 
KeyboardPowerCaseMouse
Logitech G15 600W Antec Twelve Hundred Logitech MX518 
  hide details  
Reply
post #8 of 8
Quote:
Originally Posted by NessTheHero View Post
You shouldn't rely on innerHTML. That standard has been deprecated.
I don't remember innerHTML to have ever been in the W3C specifications, however:
Quote:
Originally Posted by http://www.w3schools.com/htmldom/dom_methods.asp
The easiest way to get or modify the content of an element is by using the innerHTML property.

innerHTML is not a part of the W3C DOM specification. However, it is supported by all major browsers.
I was just looking for the easiest way to demonstrate what I mean. Creating objects and appending then to a node is somehow far more difficult than appending string.

PS. I have lots of experience with the DOM, especially DOM2 Event


Quote:
Originally Posted by NessTheHero View Post
Look into using the DOM (Document Object Model). With that, you create elements on the fly and it has better compatibility with most browsers. It's also easier to use with XML requests.
I'm interested in it. Can you give me an example?
PS. I haven't thought another way than http://en.wikipedia.org/wiki/AXAH .
EDIT43: I found it... http://www.w3schools.com/Ajax/ajax_responsexml.asp
Damn it is a lot more source code than just using the innerHTML. And if you look through other ajax tutorials at w3schools you will see that they are mostle using innerHTML.
Edited by metala - 7/20/08 at 4:02pm
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
Ferberite
(14 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Lenovo Thinkpad Edge E520 AMD Radeon HD 6630M 6GB DDR3 @ 1333MHz  
Hard DriveHard DriveOSOS
Samsung 850EVO HITACHI HTS727550A9E364 7.2krpm Debian 7.0 Win7 
OSMonitorMonitorKeyboard
Win8 15.6 Zoll 16:9, 1366x768 Pixel, AUO23EC, spiege... 24" Dell U2412M, 1920x1200 Integrated + External 
PowerCase
20V, 4.5A Lenovo Thinkpad Edge 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Quick PHP/HTML Forms question.