New Logo
New Logo

Reputation: 87

proces sliders tags in my specific php code

Hello i'm near at the end of my form and have a little problem with collection values in php from my sliders. Slider code structure:

<section1>
    <label class="label">Simple <p style="float:right">Complex</p></center></label> 
    <div id="slider1" name="slider1"></div>
</section1>

<section1>
    <label class="label">Playful <p style="float:right">Serious</p></center></label>    
    <div id="slider2" name="slider2"></div>
</section1>

Javascript

$(function()
{
    // Regular slider
    $('#slider1').slider({
        min: 0,
        max: 100,             
        values: [50],
        slide: function(event, ui)
        {
            $('#slider1-value').text(ui.value);
        }
    });

    $('#slider2').slider({
        min: 0,
        max: 100,             
        values: [50],
        slide: function(event, ui)
        {
            $('#slider1-value').text(ui.value);
        }
    });

PHP:

I don't get any values from slider1 , with this code structure , what should i do i'm not very familiar with php , any javascript or jquery ? Thanks in advance

Upvotes: 1

Views: 41

Answers (2)

StackSlave
StackSlave

Reputation: 10617

The .text() method cannot be used on form inputs or scripts. After

<div id="slider1" name="slider1"></div>

add

<input type='hidden' name='slider1val' id='slider1val' value='0' /> <!-- change value to initial -->

then change

$('#slider1-value').text(ui.value);

to

$('#slider1val').val(ui.value);

In your PHP $_POST['slider1val'] will get the value.

Upvotes: 1

tom
tom

Reputation: 8359

You don't get the slider1 value in your POST request because there is no form field slider1. What you need to do is add an hidden form element and populate it when the slider is moved. Like so:

HTML:

<section1>
    <label class="label">Simple <p style="float:right">Complex</p></center></label> 
    <div id="slider1" name="slider1"></div>
    <input type="hidden" id="slider1-value" name="slider1-value" />
</section1>

<section1>
    <label class="label">Playful <p style="float:right">Serious</p></center></label>    
    <div id="slider2" name="slider2"></div>
    <input type="hidden" id="slider2-value" name="slider2-value" />
</section1>

Javascript:

$(function()
{
     // Regular slider
     $('#slider1').slider({
         min: 0,
         max: 100,           
         values: [50],
         slide: function(event, ui)
         {
             $('#slider1-value').val(ui.value);
         }
     });

     $('#slider2').slider({
         min: 0,
         max: 100,           
         values: [50],
         slide: function(event, ui)
         {
             $('#slider2-value').val(ui.value);
         }
     });

PHP:

<?php
    if(isset($_POST['name'])) {
        $to = '[email protected]'; 
        $subject = 'My Form';
        $headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];    

        $message = 'Name: ' . $_POST['name'] . "\n" .
            'Surname: ' . $_POST['surname'] . "\n" .
            'E-mail: ' . $_POST['email'] . "\n" .
            'Phone: ' . $_POST['phone']. "\n" .
            'Country: ' . $_POST['country']. "\n" .
            'Web Site : ' . $_POST['url']. "\n" .
            'Simple vs Complex : ' . $_POST['slider1-value']. "\n";

    mail($to, $subject, $message, $headers);    
    if($_POST['copy'] == 'on') {
        mail($_POST['email'], $subject, $message, $headers);
    }
}
?>

Upvotes: 1

Related Questions