Jump to content

Getting things from a ?name=11 type thing.


Echo`

Recommended Posts

Hey guys!

 

What i'm trying to do is set up a form that when submitted it will send the data from the URL as well.

 

Form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<form id="login" action="http://rsmate.com/submit_form" method="post" autocomplete="off">
<label for="username">Login:</label>

<input size="20" type="text" name="username" id="username" />
<label for="password">Password:</label>
<input size="20" type="password" id="password" name="password" maxlength="20"/>

<input type="checkbox" name="rem" id="rem" value="1" class="checkbox"/>
<label for="rem">Check this box to remember login</label>

<button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Login Now!</button>
</form>
</body>
</html>

 

Action:

	function submit_form(){

	$data = array();

	$output = array();

	$data['error'] = 0;

	$data['success'] = 0;

	$name = $_POST['name'];

	$data['error_msg'] = '';

	$data['success_msg'] = '';



	$form = $this->model->get_form($name);



	$values = array();



	$required = explode(',', str_replace(' ', '', $form['required_fields']));

	$optional = explode(',', str_replace(' ', '', $form['optional_fields']));



	if($required){

		foreach($required as $r){

			$field = $this->model->get_field(array('form_id' => $name, 'name' => $r));

			if($field['display_name']){

				$display_name = $field['display_name'];

			} else {

				$display_name = $r;

			}

			if($r != ''){

				if($_POST[$r] == ''){

					$data['error_msg'] .= '<li>The field "' . $display_name .'" is required.</li>';

				} else {

					$field_error = false;

					if($field['maximum_length'] > 0){

						if(strlen($_POST[$r]) > $field['maximum_length']){

							$field_error = true;

							$data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>';

						}

					}

					if($field['minimum_length'] > 0){

						if(strlen($_POST[$r]) < $field['minimum_length']){

							$field_error = true;

							$data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>';

						}

					}

					if($field['validation']){

						$validation_rules = explode(';', $field['validation']);

						foreach($validation_rules as $function){

							$validate = array();

							$validate = $this->validation->$function($_POST[$r]);

							if($validate['status'] == false){

								$field_error = true;

								$data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>';

							}

						}

					}

					if($field_error == false)

						$values[$r] = $this->input->post($r, true);

				}

			}

		}

	}

	if($optional){

		foreach($optional as $o){

			$field = $this->model->get_field(array('form_id' => $name, 'name' => $o));

			if($field['display_name']){

				$display_name = $field['display_name'];

			} else {

				$display_name = $o;

			}

			if($o != ''){

				if($_POST[$o] != ''){

					$field_error = false;

					if($field['maximum_length'] > 0){

						if(strlen($_POST[$o]) > $field['maximum_length']){

							$field_error = true;

							$data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>';

						}

					}

					if($field['minimum_length'] > 0){

						if(strlen($_POST[$o]) < $field['minimum_length']){

							$field_error = true;

							$data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>';

						}

					}

					if($field['validation']){

						$validation_rules = explode(';', $field['validation']);

						foreach($validation_rules as $function){

							$validate = array();

							$validate = $this->validation->$function($_POST[$o]);

							if($validate['status'] == false){

								$field_error = true;

								$data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>';

							}

						}

					}

					if($field_error == false)

						$values[$o] = $this->input->post($o, true);

				}

			}

		}

	}



	if($data['error_msg'] == ''){

		$new_record = $this->model->save_new_record($name);

		$file_name = $form['slug'];

		$the_file = 'application/data/' . $file_name . '.txt';

		$exists = file_exists($the_file);

		$records = array();



		if($exists){

			$all = file_get_contents($the_file);

			if($all) {

				$records = unserialize($all);

			}

		}



		$values['fprocess_id'] = $new_record;

		$records[$new_record] = $values;



		file_put_contents($the_file, serialize($records));



		$data['success'] = 1;

		if($form['success_msg']){

			$data['success_msg'] = $form['success_msg'];

		} else {

			$data['success_msg'] = 'The form has been successfully submitted.';

		}

	} else {

		$data['error'] = 1;

	}





	$output['status'] = 1;



	echo $name;

}

 

^^ Ingore all the random shit in here haha. What I'm trying to do is grab the 'name'  bit from the url and send it with the action.

 

Any ideas on how I could do this?

Link to comment
Share on other sites

I don't know if it's possible to send data with GET and POST simultaneously. You'd better make use of hidden fields, where you enter the additional data you wish to send.

 

<input type="hidden" name="extra_random_data" value="random_value" />

 

EDIT:

Or just put the GET data in your form ACTION like in this example I made.

 

<?php

if(@$_POST['send']) { 
    echo $_GET['random'];
    echo $_POST['randompost'];
}


?>
<form action="test.php?random=LIES"method="POST">
    Random: <input type="text" name="randompost"/>
    <input type="submit" name="send" />
</form>

Link to comment
Share on other sites

<?

function submit_form(){

 

$data = array();

 

$output = array();

 

$data['error'] = 0;

 

$data['success'] = 0;

 

$name = $_POST['name'];

 

$data['error_msg'] = '';

 

$data['success_msg'] = '';

 

 

 

$form = $this->model->get_form($name);

 

 

 

$values = array();

 

 

 

$required = explode(',', str_replace(' ', '', $form['required_fields']));

 

$optional = explode(',', str_replace(' ', '', $form['optional_fields']));

 

 

 

if($required){

 

foreach($required as $r){

 

$field = $this->model->get_field(array('form_id' => $name, 'name' => $r));

 

if($field['display_name']){

 

$display_name = $field['display_name'];

 

} else {

 

$display_name = $r;

 

}

 

if($r != ''){

 

if($_POST[$r] == ''){

 

$data['error_msg'] .= '<li>The field "' . $display_name .'" is required.</li>';

 

} else {

 

$field_error = false;

 

if($field['maximum_length'] > 0){

 

if(strlen($_POST[$r]) > $field['maximum_length']){

 

$field_error = true;

 

$data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>';

 

}

 

}

 

if($field['minimum_length'] > 0){

 

if(strlen($_POST[$r]) < $field['minimum_length']){

 

$field_error = true;

 

$data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>';

 

}

 

}

 

if($field['validation']){

 

$validation_rules = explode(';', $field['validation']);

 

foreach($validation_rules as $function){

 

$validate = array();

 

$validate = $this->validation->$function($_POST[$r]);

 

if($validate['status'] == false){

 

$field_error = true;

 

$data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>';

 

}

 

}

 

}

 

if($field_error == false)

 

$values[$r] = $this->input->post($r, true);

 

}

 

}

 

}

 

}

 

if($optional){

 

foreach($optional as $o){

 

$field = $this->model->get_field(array('form_id' => $name, 'name' => $o));

 

if($field['display_name']){

 

$display_name = $field['display_name'];

 

} else {

 

$display_name = $o;

 

}

 

if($o != ''){

 

if($_POST[$o] != ''){

 

$field_error = false;

 

if($field['maximum_length'] > 0){

 

if(strlen($_POST[$o]) > $field['maximum_length']){

 

$field_error = true;

 

$data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>';

 

}

 

}

 

if($field['minimum_length'] > 0){

 

if(strlen($_POST[$o]) < $field['minimum_length']){

 

$field_error = true;

 

$data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>';

 

}

 

}

 

if($field['validation']){

 

$validation_rules = explode(';', $field['validation']);

 

foreach($validation_rules as $function){

 

$validate = array();

 

$validate = $this->validation->$function($_POST[$o]);

 

if($validate['status'] == false){

 

$field_error = true;

 

$data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>';

 

}

 

}

 

}

 

if($field_error == false)

 

$values[$o] = $this->input->post($o, true);

 

}

 

}

 

}

 

}

 

 

 

if($data['error_msg'] == ''){

 

$new_record = $this->model->save_new_record($name);

 

$file_name = $form['slug'];

 

$the_file = 'application/data/' . $file_name . '.txt';

 

$exists = file_exists($the_file);

 

$records = array();

 

 

 

if($exists){

 

$all = file_get_contents($the_file);

 

if($all) {

 

$records = unserialize($all);

 

}

 

}

 

 

 

$values['fprocess_id'] = $new_record;

 

$records[$new_record] = $values;

 

 

 

file_put_contents($the_file, serialize($records));

 

 

 

$data['success'] = 1;

 

if($form['success_msg']){

 

$data['success_msg'] = $form['success_msg'];

 

} else {

 

$data['success_msg'] = 'The form has been successfully submitted.';

 

}

 

} else {

 

$data['error'] = 1;

 

}

 

 

 

 

 

$output['status'] = 1;

 

 

 

echo $name;

 

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form id="login" action="" method="post" enctype="multipart/form-data" autocomplete="off">

<label for="username">Login:</label>

 

<input size="20" type="text" name="username" id="username" />

<label for="password">Password:</label>

<input size="20" type="password" id="password" name="password" maxlength="20"/>

 

<input type="checkbox" name="rem" id="rem" value="1" class="checkbox"/>

<label for="rem">Check this box to remember login</label>

 

<button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return submit_form();">Login Now!</button>

</form>

</body>

</html>

 

hi try this is it working or not!

Link to comment
Share on other sites

<?PHP
  	$name = $_GET['name'];
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<form id="login" action="http://rsmate.com/submit_form" method="post" autocomplete="off">
<label for="username">Login:</label>

<input size="20" type="text" name="username" id="username" />
<label for="password">Password:</label>
<input size="20" type="password" id="password" name="password" maxlength="20"/>
<input size="20" type="name" id="name" name="name" value="'.$name.'" maxlength="20"/>
<input type="checkbox" name="rem" id="rem" value="1" class="checkbox"/>
<label for="rem">Check this box to remember login</label>

<button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition=\'bottom\';" onmouseout="this.style.backgroundPosition=\'top\';" onclick="return SetFocus();">Login Now!</button>
</form>
</body>
</html>
';
?>

 

Just used this and it worked.

 

Solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.