Hello,

I would like to solve form validation and filename problem.

Here is my code:

    /************************** Step 1: Select Cell************************************/

    if(isset($_POST['SmartPhone']))
    $checked1=$_POST['SmartPhone'];
    $form->add_checkbox('SmartPhone','SmartPhone',$checked1);

    if(isset($_POST['Apple']))
    $checked2=$_POST['Apple'];
    $form->add_checkbox('Apple','Apple',$checked2);

    /************************** Step 2: Select Model************************************/

    if($_POST['SmartPhone']==false and $_POST['Apple']==false)
    {
    $this->add(new error('<span style="color:red">Select your cell..!!</span>'));
    $this->step1();
    return;
    }
    if(isset($_POST['S4']))
    $tech2=$_POST['S4'];
    $form->add_checkbox('S4','S4',$tech2);

    if(isset($_POST['iPhone 5']))
    $tech3=$_POST['iPhone 5'];
    $form->add_checkbox('iPhone_5','iPhone 5',$tech3);

    if(isset($_POST['iPhone 5s']))
    $tech1=$_POST['iPhone 5s'];
    $form->add_checkbox('iPhone_5s','iPhone 5s',$tech1);

    //In addition, i want to know how to put "Select All" button here
    // in order to SELECT ALL MODELs: S4, iPhone 5, iPhone_5s
    /************************** Step 3: File Generation************************************/

    if($_POST['S4']==false and $_POST['iPhone_5']==false and $_POST['iPhone_5s']==false)
    {
    $this->add(new error('<span style="color:red">Please enter your model..!</span>'));
    $this->step2();
    return;
    }

    $date = date('Y-m-d_H-i-s');

    // Filename should be like this format "cell_datetime.xml"
    // For example: SmartPhone_20130910183023.xml or Apple_20130910183023.xml

    // Any idea how to create such filename??

**Problems: **

  1. IF we don't select Model; it gives message for both to select again. It should ask ONLY for model.

  2. Input for Select All button

  3. Input for Filename

Thanks in advanced for your time. :)

Member Avatar for diafol

IF we don't select Model; it gives message for both to select again. It should ask ONLY for model.

Both what?

Input for Select All button

What do you need - a way of creating a select / deselect all? If so, that's javascript not php.

Input for filename

I'm assuming you want a way to create a filename based on make and date.

$filename = $make . '_' . date('YmdHis) . '.xml';

Both what?

To select Cell and Model

What do you need - a way of creating a select / deselect all?

Yes, i got it. I will put in JavaScript forum.

I'm assuming you want a way to create a filename based on make and date.

What is $make ?? I have given example of filename.

Filename should be generated Based on "selected Cell".

**For example if i select SmartPhone then filename should be like this: **

**SmartPhone_20130910183023.xml **

Member Avatar for diafol

I'm confused can the 'selected cell' be Apple AND SmartPhone? If not, I'm stuggling to understand why there would be different $_POST variables - I would expect a pair of radiobuttons or maybe a dropdown, to choose between them.

$make was my way of keeping the string 'Apple' or 'SmartPhone'.

for creating the file you can use the fopen() funtion, if there no file the function will create one

$make was my way of keeping the string 'Apple' or 'SmartPhone'.

So, if i am not mistaking, to save cell for filename, i have to use javascript.

for creating the file you can use the fopen() funtion

First step is to get filename as expected. Yes, i can use fopen function.

Member Avatar for diafol

So, if i am not mistaking, to save cell for filename, i have to use javascript.

That's not what I'm saying.
Can you tell us if a form can choose to be Apple, SmartPhone or Both at the same time? Showing your html form would help too.

Showing your html form would help too.

I have written in my question all that i have.

Well, for html it is function like this:

 public function add_checkbox ( $name, $title, $checked=false,$disabled=false )
  {
    $this->buffer .= "<div class=\"formline\">\n";
    $this->buffer .= "<div class=\"formlabel\"></div>";
    $this->buffer .= "<div class=\"formfield\"><input type=\"checkbox\" class=\"chkbox\" name=\"$name\" value=\"true\"";
    if ( $checked )
      $this->buffer .= " checked=\"checked\"";
    if ( $disabled )
      $this->buffer .= " disabled=\"disabled\"";
    $this->buffer .= " /> $title</div>\n";  
    $this->buffer .= "</div>\n";

  }

Problems

  • IF we don't select Model; it gives message for both to select again. It should ask ONLY for model.
  • Input for Select All button

what about an "if" "else if" "else" statement to activate only one at a time?

i think you want to do something like this right?
Click Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.